JanS
JanS

Reputation: 43

How to let Jenkins build the correct .war file?

I am building a Webapplication for a Tomcat Server with the help of Maven and Jenkins.

The Problem ist, that the Structure of the .war file after unpacking by Tomcat is not in a way that it works, neither in a "tomcat conform" way (https://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html).

How can i fix this?

Details: This is a project I took over, not one i build by myself. This is the source code structure

This is the Jenkins unpacked .war file structure

This is the structure how it is needed on the server. (tomcat standard conform, as i see it)

Upvotes: 1

Views: 2100

Answers (1)

khmarbaise
khmarbaise

Reputation: 97517

You should follow the maven conventions for folder layout which means src/main/java for source like Java files. Within src/main/webapp/ things which belong more to web apps only..Like web.xml, jsp files etc. Furthermore you need to set the correct <packaging>..</packaging> in your pom file which is war in your case.

 |-- pom.xml
 `-- src
     `-- main
         |-- java
         |   `-- com
         |       `-- example
         |           `-- projects
         |               `-- SampleAction.java
         |-- resources
         |   `-- images
         |       `-- sampleimage.jpg
         `-- webapp
             |-- WEB-INF
             |   `-- web.xml
             |-- index.jsp
             `-- jsp
                 `-- websource.jsp

Apart from that i would recommend that you first create your war file on command line and don't use Jenkins in the first steps otherwise you more sources of errors in your project. If the war file will be created correctly and can be deployed to Tomcat manually without any problem you can go a step further and use a CI solution like Jenkins.

Upvotes: 3

Related Questions