No EAR, no WAR but a jar for your webapp

Simplify your deployment package.

– An Ear requires a lot of configuration and nested elements (some DB config xml files, some jars and some wars)
– A War requires some xml files, jsps and some jars
– A jar needs some classes, that’s all.

It would be neat to use the third option, for ease of use and installation. After all, the jar needs no more than itself to start.
An example of a web app project using this tip : jenkins
java -jar jenkins.war (the file can be launched as a java app or as a war webapp without any difficulty)

So, how to install this idea into your webapp project ?
1) Integrate the jetty server dependency into your project :

<dependency>
<groupid>org.eclipse.jetty</groupid>
<artifactid>jetty-server</artifactid>
<version>9.2.14.v20151106</version>
</dependency>
<dependency>
<groupid>org.eclipse.jetty
<artifactid>jetty-webapp
<version>9.2.14.v20151106
</dependency>
</code>

2) Write a server start class :
https://github.com/libetl/GenericRestWebApp/blob/master/src/main/java/org/toilelibre/libe/restwebapp/ioc/webapp/ServerMain.java

3) Add a plugin to bundle your sources into a jar :

<plugin>
<artifactid>maven-assembly-plugin</artifactid>
<configuration>
<archive>
<manifest>
<mainclass>org.toilelibre.libe.restwebapp.ioc.webapp.ServerMain</mainclass>
</manifest>
</archive>
<descriptorrefs>
<descriptorref>jar-with-dependencies</descriptorref>
</descriptorrefs>
<finalname>${project.build.finalName}</finalname>
<appendassemblyid>false</appendassemblyid>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package

4) Type `mvn install` and wait. Your jar is now ready to be started with `java -jar yourproject.jar`