Skip to main content

Deploy Ant project in Tomcat using Jenkins


Setup Ant in Jenkins:
1. Download the Ant Binary Distribution from its official site.

2. Unzip the downloaded Ant file.

3. Go to Manage Jenkins  and click on  Configure System


4. Scroll down and Go to Ant Installation and click Add Ant.

5. Uncheck the Install Automatically , another wise it will download the Ant online,
After unchecking the Install Automatically it will show textfield for ANT_HOME.

6. You can specify Ant Name any name that you want to use for referering the particular Ant,
And in ANT_HOME you need to specify the location for Ant where the Extracted Ant is available.

7. After that apply and save the changes.


Install Tomcat Deployment plugin in Jenkins:

1. Go to Manage Jenkins  and click on Manage Plugin


2. Open Available tab and Select  Deploy To Container plugin and Install it using Install without Restart.


3. After that is Start the installation  and redirect you to Installing Plugins/Upgrades page.

4. Now select the Restart Jenkins when installation is complete and no jobs are running checkbox.


Create Ant Project using Netbeans :

1. Choose File > New Project  from the main menu. Select the Java Web category, then select Web Application. Click Next.
The New Project wizard allows you to create an empty web application in a standard IDE project.


2. In Project Name, enter JenkinsTest. Also, specify the location for the project on your computer. Click Next.

3. In the Server and Settings panel, specify the Tomcat server as server which will be used to run the application.

4. In the Java EE Version field, select Java EE 5. 


5. Click Finish. The IDE creates a project template for the entire application, and opens an empty JSP page (index.jsp) in the editor. The index.jsp file serves as the welcome page for the application.


Create Job for Build Creation and Deployment in Jenkins:

1. Go to New Items and specify the Item name "JenkinTestDeployment" and select Freestyle project.



2. In the Item Configuration specify Project name  "JenkinTestDeployment" and Set the Source Code Management  to None.

3. In the build section, select Execute Shell and add the following command
cp -R [ProjectLocation] [Jenkin_WorkSpace]

4. Also add Invoke Ant in the Build Section.

5. In the Ant Version select the configured Ant and add the build.xml in Build File


6. In Post-Build Action, select Deploy war/ear to a container and specify the war location and Tomcat manager-script user credentials.


7. Apply and Save the item

8. After the Deploy the build using Build Now button
9. You can check the console log for the build status and errors.



Comments

Popular posts from this blog

Change Tomcat JSESSION Cookie Name and Path

Sometime we have a scenario that two different tomcat application running on same domain,  and you want to share a session cookie in between them, there are two problem will come in this scenario i.e: 1. Session Cookie Name : As both the application have same cookie name i.e JSESSIONID , so its difficult to know which JSESSIONID belongs to which application , so in this scenario we need to change the Session cookie name. 2. Cookie Path :  By default tomcat create a session cookie for the app context, due to which we can't share the cookies between two application , so we need to change the cookie path from  context to the root. For doing the above point we can use  ServletContextListener or   web.xml file. 1. ServletContextListener import javax.servlet.SessionCookieConfig; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class MyTestListener implements ServletContextListener  {     public void contextInit

Deploy application at ROOT(/) context in Tomcat

Tomcat has its own application with the name "ROOT" that is runing in the main root (/) context path, So when ever you install new tomcat and try to accesss  http://localhost:8080/  then it will show you the default tomcat home page, If you want to deploy you application at  http://localhost:8080/  then there is two way to do this 1. ROOT.war : Create your application war file with the name ROOT.war and place it in the [TOMCAT_HOME]/webapps/ directory and restart tomcat services 2. Server.xml : If you can't change the war file name then in server.xml file there is one context tag  that is use to map your application on any context Remove the ROOT folder directory from [TOMCAT_HOME]/webapps/ Copy your application war file into the same directory , let suppose your application war file name is "app.war". Edit the server.xml file located at [TOMCAT_HOME]/conf/server.xml, and add the context tag < Context path = "/" docBase = "app&

Encode from JavaScript and Decode at Java.

if you have a senerio like you want to send encoded parameter values from your web page  and decode them  at server side then this blog may be help you. JavaScript: Before submit the form I am encoding all the value entered by user so that it can not be read by humanly, for encoding the values I have written a method named  encodeBase64 <script> function encodeBase64(input){         var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";         input = escape(input);         var output = "";         var chr1, chr2, chr3 = "";         var enc1, enc2, enc3, enc4 = "";         var i = 0;              do {             chr1 = input.charCodeAt(i++);             chr2 = input.charCodeAt(i++);             chr3 = input.charCodeAt(i++);                      enc1 = chr1 >> 2;             enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);             enc3 = ((chr2 & 15) << 2