Kapil Kaushal
Kapil Kaushal

Reputation: 49

How to build WAR file using jenkins

I need some help with the Java code for my web application. I need to create a WAR file of my java code uploaded on stash using jenkins and deploy it to nexus. Finally from nexus i need to deploy the WAR file to my tomcat instance to run the application.

I am not sure how jenkins is going to create a WAR file. Can someone please advise.

Upvotes: 0

Views: 11388

Answers (2)

JRichardsz
JRichardsz

Reputation: 16505

You don't need Jenkins to create the war file. A war file could be created with:

Create war file using Jenkins

You could install ant or maven plugin in order to execute necessary commands.

Also you can use single shell execution ( in build section on Jenkins project) and execute your ant or maven commands.

Deploy war to nexus

Again, Jenkins is not a magician. Jenkins needs another tools to use nexus.

You could install the nexus plugin for Jenkins or just execute command line sentences directly to nexus.

Deploy war in tomcat

Tomcat has two ways to deploy any war file:

  • just copy and paste the war file into webapps folder
  • enable manager in tomcat and upload the war using tomcat http endpoints.

Again, Jenkins could use any of the previous approaches. Just install the tomcat plugin or execute command line sentences.

Advice

Create the war, upload it to nexus and deploy it to tomcat using shell without Jenkins. If you can do this without any error, put these steps in Jenkins with:

  • Simple free style project
  • scripted pipeline
  • declarative pipeline

If you start with Jenkins configurations you will get confuse errors and you could lost time.

Upvotes: 1

Ian W
Ian W

Reputation: 4767

@jrichardsz answer provides substantial good direction, but your response suggests you should reconsider your question, re: strategic tool" and "implement CI/CD".

Jenkins is CI/CD tool. It orchestrates tasks, including building (war using ant/maven) and deploying (nexus and tomcat env), as well as testing and all sorts of other tasks. You needs to understand the individual steps you need to execute, then understand how to orchestrate them in Jenikns. Review https://jenkins.io/doc/ for the second part.

ps: recommend using maven over ant for Java and use tomcat manager or jenkins plugins to deploy war rather than copy/paste.

Upvotes: 0

Related Questions