How to deploy java application(war) to EC2 using jenkins? How to deploy java application(war) to EC2 using jenkins? jenkins jenkins

How to deploy java application(war) to EC2 using jenkins?


Step 1. Install Jenkins plugin

Open your favorite browser and navigate to Jenkins. Log in and select “Manage Jenkins” followed by “Manage Plugins”. Select the “Available” tab, locate the “Deploy to container” plugin and install it.

Step 2. Edit tomcat-users.xml

In order for Tomcat to accept remote deployments, you have to add a user with the role manager-script. To do so, edit the file ../conf/tomcat-users.xml and add the following line:

<user username="deployer" password="deployer" roles="manager-script" />

Step 3. Edit the Jenkins job

Back in Jenkins, go to your job and select “Configure”. Next, scroll down to the bottom of the page to the “Post-build Actions”. Select the option “Deploy war/ear to a container” from the “Add post-build action” dropdown button. Fill in the new fields.

Step 4. Run the Job project and verify the end results

Schedule a build for your job in Jenkins. If you check out the log file you should see one or more lines near the end indicating that the war file has been deployed.

If you check the logfiles in Tomcat (catalina.out) you should also see that your application has been succesfully deployed.

Lastly, if you point your browser to the URL and context path you’ve specified in the job configuration in Jenkins (e.g., http://your-server:8080/mywebapp), you should be able to open your freshly deployed application.

Credits to Jdev.itMore info can be found here


With EC2 (or any other deployment practice too), first determine your production servers are going to be mutable or immutable.

[Mutable]The servers will be running forever, and you perform on-going updates as explained in the blogpost mentioned above (elizabetht) for Java war, or many other ways for different languages/platform.

[Immutable]The servers are re-created (vs. upgraded) by automation mechanism such as scripting, or using config. mgmt tools like Puppet/Chef/Ansible or vendor specific initialization mechanism like AWS Userdata/Docker dockerfile/Vagrant vagrantfile, or using many other provisioning tools.

Generally speaking databases or queues should be Mutable category, and all other compute nodes are better be Immutable category. The benefits of Immutable category are a lot including easy HA, disaster recovery and also enables Blue/Green deployment and much more.