问题
I use the mvn jetty:run
goal from the maven jetty plugin to start my web application project, built using maven.
Now I want to create a fat jar with embedded Jetty so that I will be able to start my app using java -jar
.
Is there a way to use the maven jetty plugin to generate a fat jar with embedded Jetty?
回答1:
MarianP already answered your question in the comment.
Add your jetty dependencies in your pom.xml
<!-- jetty dependencies -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
Add the shade plugin like so:
<!-- maven shade plugin, executable uber Jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>YourMainClassHere</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Then add your server/client from your main()
来源:https://stackoverflow.com/questions/31295771/generate-a-jar-with-embedded-jetty-using-maven-jetty-plugin