Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven plugin to generate an executable web application (war->executable jar-war)

I have a maven project that is generating a .war file.

I want to configure maven to generate an executable jar, that embeds a servlet container (jetty, tomcat, or others) plus my war application, and generate an executable jar that can run my web application with a command like:

java -jar mywebapp.war

Is there a maven plugin to obtain such artifact?

At the moment I'm using jetty-runner to run a test version of my app, it's quite satisfying for test, but not as as handy for redistribution as it would be an executable war (like in jenkins).

Update

@jesse-mcconnell: I don't want to change a single line in my web application (except in the pom.xml) to achieve the result. It's just a matter to package my war differently, and keep it deployable under an appserver of choice, plus having the ability to run it as an executable war.

A perfect solution should also give me the ability to choose which appserver to embed, also specifying all needed configuration files contained in the executable war itself.

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

A perfect solution could generate a war containing stuff like this:

├── 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 
  1. Main.class should use etc configuration as default, but being able to override common parameters at the command line (port, context,etc) or specifying a new configuration.
  2. Main.class should be able to load the container jar and configuration from inside the container (or extract into tmp.dir) and start up the appserver.

This is how I would make it.

At the end, you have a normal war, that can be deployed in any appserver, with the ability to run in a self-contained way.

like image 263
Luigi R. Viggiano Avatar asked Jan 14 '23 14:01

Luigi R. Viggiano


1 Answers

Tomcat Maven plugin do that have a look here http://tomcat.apache.org/maven-plugin-2.0/executable-war-jar.html

HTH

like image 76
Olivier Lamy Avatar answered Jan 31 '23 08:01

Olivier Lamy