Maven plugin for creating an executable web application (war-> executable jar-war)

I have a maven project that generates a .war file.

I want to configure maven to create an executable jar that embeds a servlet container (berth, tomcat or others) plus my military application and generates an executable jar that can launch my web application using a command, for example:

java -jar mywebapp.war 

Is there a maven plugin to get such an artifact?

At the moment I am using jetty-runner to run a test version of my application, this is quite satisfactory for the test, but not as convenient for redistribution as it is for an executable war (for example, for jenkins).

Update

@ jesse-mcconnell: I do not want to change one line in my web application (except pom.xml) to achieve the result. It is just a matter of sharing my war in different ways and keeping it deployed under the selected application server, as well as being able to launch it as an executable war.

The ideal solution should also give me the opportunity to choose which application server will be deployed, as well as specify all the necessary configuration files contained in the executable war itself.

@khmarbaise: I know about jenkins, I already checked the code a long time ago, it uses the winstone servlet container and it puts Main.class in a war accessible from http (and I think this is wrong)

An ideal solution can create a war containing such things:

 ├── META-INF │ └── MANIFEST.MF (Main-Class: WEB-INF.container.classes.Main) └── WEB-INF  ├── web.xml  ├── classes  ├── lib └── container ├── lib (jetty.jar/tomcat.jar/whatever.jar)  ├── etc (configuration files for the container) └── classes └── Main.class 
  • Main.class should use the default configuration etc, but is able to override the general parameters on the command line (port, context, etc.) or specify a new configuration.
  • Main.class should be able to load the container container and configuration from the container (or extract it to tmp.dir) and start the application server.

This is how I do it.

In the end, you have a normal war that can be deployed on any application server, with the ability to run in an autonomous way.

+4
source share
3 answers

Use the maven jar plugin to set the Main-Class in the manifest, and then write the main method with something similar to this (or that calls such code):

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java? h = jetty-8

You can register your servlets and connect webapp accordingly.

The problem with linking a war file to a file in a jar file is that you will need a specialized deployer that understands that deploying a war file from inside a jar is not a normal thing. So creating a uber type bank is probably the best way to go. In addition, one of the main reasons for the actual WebAppContext is the isolation of the class loader, which is kind of controversial in these cases.

You can use the maven-dependency plugin to unpack the various dependencies you need. There are other plugins that you can use, for example, as maven-uberjar-plugin (I think it was a name), but you can do it simply with maven-dependency-plugin + a custom main class that looks like something sort of higher.

I like this approach, because in the end you get the main method that you can run in eclipse, which launches the entire application and allows you to debug all this and also often win.

Edit: for posterity, the jetty also releases with an artifact called jetty-runner, which allows you to run military files directly from the command line

+3
source

Not that I know, but check out the jenkins source code that supports , starting with the command, how you expected to work.

+2
source

All Articles