Pages

Showing posts with label build-tools. Show all posts
Showing posts with label build-tools. Show all posts

Thursday, February 20, 2014

What is jenkins?

Read the article

https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Sunday, July 21, 2013

How to install a custom maven dependency to your local repository

This is very easy to do. Open a terminal and enter the following command.

mvn install:install-file -Dfile=c:\customBuiltjar-{version}.jar -DgroupId=your.jar.groupid  -DartifactId=customBuiltjar -Dversion={version} -Dpackaging=jar

Here the -Dfile parameter indicates the path to jar file. Also replace the -DgroupId with your group id for the dependency.

Thursday, July 4, 2013

maven compile error -maven compile annotations are not supported in source 1.3

This error occurs because maven by default uses jdk 1.3 for compiling. As you know java 1.3 does not support annotations. So in order to avoid this error you need to use a newer version of java. Maven provides a plugin to compile your code to a specific java version. Add the following in your pom.xml source code. Then it should do the trick.


                  <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>

Thursday, September 20, 2012

Ant Vs Maven

Well this has been a highly debated topic among java developers. Some prefer ant while other maven. So what is the better build tool.

Imho i think both have their advantages and disadvantages. if you use ant

  • your project directories are not predefined, therefore flexible. You can build the project in your own way.
  • Unlike maven you do not need internet to work.
  • Unlike maven there will be no conflicting jar downloads or broken dependencies since developer him/her self mentions adds the libraries.
  • But you need to manage the dependencies of the dependencies which sometimes is a headache.
  • Easy setup and usage.
  • Not the best tool if the project is huge.
  • Support for managing versions of dependencies and the project it self is not good.
Let's see the maven facts
  • You can just put dependencies in the pom.xml file and maven will download it for you.
  • You do not need to manage dependencies of dependencies, since maven automatically handles it.
  • You can manage versions of the project, dependency versions easily.
  • Good if the project is large.
  • Project structure is not flexible. You will have to go with default maven structure.
  • You have to have internet to work with.
  • There may have broken dependencies.
yes as you see both has it's own advantages and disadvantages. However as a java developer I believe you need to learn both the build tools since the type of tool you need to work with will vary from project to project. In my case it's 50-50. So I wouldn't fancy only one build tool but both.

Saturday, September 15, 2012

How to get a maven web project work or run in eclipse

I must confess you that it had been a real waste of time. I literally had to search the whole web to find a descent tutorial to get a maven built project work with eclipse.

That is when you create a maven web application in eclipse (obviously after setting up maven in eclipse. you can find many online tutorials on how to setup maven  in eclipse) you won't be able to run the project by just right clicking on the project and select run on server.

Finally after spending several hours, I found a nice tutorial.

In order to do that you need to do some stuff. The following link has a nice simple video tutorial on how to do this very easily. Hope this is useful.

http://www.youtube.com/watch?v=Q14WkL9mw5o&feature=related

Thursday, August 9, 2012

Maven building and compiling the first App

In the last post I described how to set up maven in linux environment. Now let's see how to create a project structure, compile, package and install.

First open a terminal, then make a directory called TestAppDir and go to the folder. 
  • Now type in the terminal:  mvn archetype:generate Note that when you run this command for the first time it will download the dependency jars and pom files. Now this command will show you a list. The list contains various architectures (spring apps, hibernate etc...).  Lets not input anything and press enter (This will generate a folder structure with default archetype).
  • Now you will be asked the following
Choose org.apache.maven.archetypes:maven-archetype-quickstart version: 
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1

Enter 6 (Latest version). If you run this for the first time this will download the dependencies as well.

Then you will be asked to fill the following


Define value for property 'groupId': : mad.maven.test
Define value for property 'artifactId': : MadTest
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  mad.maven.test: :
Confirm properties configuration:

the values mad.maven.test is given by me and it is like the package name in a normal program. The name I have given for the artifactId is MadTest. So when you package the app, it will  be like MadTest.jar. version refers to the version of the app you are creating. in the test package, you can write all the test cases. 

Now you will see a directory called MadTest in side TestAppDir. Now go to the MadTest directory. There you will see a pom.xml open it using a text editor. You will see something like below.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mad.maven.test</groupId>
  <artifactId>MadTest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MadTest</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

The group id, artifact id, version, name are given by you. Packaging tag indicates the type of file you will get after packaging the app. If you have war, it will package app in to a .war file. All the dependencies are mentioned inside dependency tags. By default maven will include junit as a dependency to run unit tests in the test directory within your app.

Now go back to the MadTest directory.  You can enter below commands


  • mvn compile : This will compile your code.
  • mvn test : This will run the unit tests in the app
  • mvn package : This will package your app in to a file you specified in the pom.xml file. In this case it is a .jar file.
Now let's say you need you put a logging code inside your source code, like

Logger logger = LoggerFactory.getLogger(App.class);
        logger.info("Hello World !!!");

Now to work this code you need slf4j jar as a library and import it in the code. 
put,
import org.slf4j.*;

Now with maven, you do not need to download manually and put it in the libraries. Instead go to 


and put slf4j in the search box. Then go to the SLF4J Api module link and choose the version you want and click on the version number. If you choose 1.6.6, you will see something like below in that page.

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>

put this code inside dependencies tags in your pom.xml.
Then in the terminal go to the MadTest directory and type mvn compile. Now the dependent slf4j will be automatically be downloaded at the compile time. Then type mvn package. Now you will see the jar file in the target folder.

Now if you type mvn install in the terminal from the same directory, the app will be available in your local maven repository.

Wednesday, August 8, 2012

An introduction to maven : How to setup maven manually

Maven is a built tool like ant. It is mainly used in building a program and project management. First the question is why do we need maven? below are some of the reasons to why we need maven.

  • It is very much likely that a program use jar libraries. We need to make sure these jars are available at the compile time, when bundling the program. Maven helps us in this regard.
  • Another problem is dependencies. A jar in the program may require another jar. May be the jars needed may need to have specific versions. This can be handled using maven.
  • To set a project structure, we can use maven.
  • To build, publish and to deploy.
Second question is how to set up maven? This is described below. This is very easy.
  • download maven from http://maven.apache.org/download.html
  • Then extract it to some location
  • open a terminal and type:           export MQ_HOME=/home/madhumal/apache-maven-3.0.4
  • Then type:                    export PATH="$PATH":/home/madhumal/apache-maven-3.0.4/bin
  • Now type :                    mvn --version
  • You will get the maven version and that is it. Not that the MQ_HOME is the path where you extracted maven binaries.
Alternatively the NetBeans IDE has inbuilt support for maven as well.

I will post more about maven in later posts.