How to compile Freestyle/Simple Java Project in Jenkins?

UPDATED: 24 February 2015
Jenkins Freestyle Project Logo

We were trying to set-up simple Java Project with ANT. There ain't any simple article available over Internet and it took hours to set-up so I thought let me share my experience with you.

Step 1: Create Simple Java Project using Eclipse.

Step 2: Open Jenkins and Click "New Item", Provide Job name, Select "Freestyle Project" and Click OK to create new Jenkins Job. Follow the image.



Step 3: On next page click on "Advance" under Advanced Project Options. Follow the image.



Step 4: Select "Use custom workspace" and Provide Directory path and Display name. Follow the image.



Step 5: Under Build section select "Ant Version". Target is name of <target> tag in build.xml. You can choose it as per you convenient but it should be same in build.xml and here in Jenkins. Follow the image.



Step 6: Click on "Advanced" under Build section and write "Build File" name commonly used build.xml. Follow the image.



Step 7: Click on "Apply"

Step 8: Create "build.xml" under root directory of your project. Follow the image.


Step 9: Copy paste the following content in your build.xml. Change Project name and default value (*if applicable)
<?xml version="1.0" encoding="UTF-8"?>
<project name="JenkinsSampleProject" default="compile" basedir=".">
 <!-- ANT will start execution from here by finding target "compile"  -->
 <target name="compile" depends="clean">
  <!-- Java compile parameters here  -->
  <javac debug="true" debuglevel="lines,vars,source" srcdir="src" destdir="bin" />
 </target>

 <!-- "compile" target depends on "clean" so It'll delete "bin" folder if exists and 
   create new "bin" folder for compiles class file -->
 <target name="clean">
  <delete dir="bin" />
  <mkdir dir="bin" />
 </target>
</project>

Step 10: Go to Jenkins and click on "Build Now"


0 comments :