我使用maven jetty plugin中的mvn jetty:run
目标来启动使用maven构建的Web应用程序项目。
现在我想创建一个带有嵌入式Jetty的胖jar,以便我可以使用java -jar
启动我的应用程序。
有没有办法使用maven jetty插件生成带有嵌入式Jetty的胖罐?
答案 0 :(得分:3)
MarianP已在评论中回答了您的问题。
在pom.xml中添加您的jetty依赖项
<!-- 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>
像这样添加阴影插件:
<!-- 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>
然后从main()
添加您的服务器/客户端