我正在尝试生成一个包含将启动 Jetty的main()的 .jar。
我的问题是我希望将 Jetty 加载的 .war包含在同一个 .jar中。
我已经能够创建包含 .war 的 .jar :
在 POM.xml 中:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<finalName>myApp</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.myApp.Server</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/executable-jar-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
可执行 jar-assembly.xml :
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies-and-war</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>target/classes/</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>
myApp.war
</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
在 Jetty 中设置战争的代码:
handler.setWar("myApp.war");
...我也试过:
URL res = Server.class.getResource("myApp.war");
handler.setWar(res.toExternalForm());
... 和 :
URL res = Thread.currentThread().getContextClassLoader().getSystemResource("myApp.war");
handler.setWar(res.toExternalForm());
但没有任何效果!
使用最后一个示例代码启动 Jetty,服务器似乎可以正确启动,但没有请求工作。配置明显不对。
我知道有一些解决方法可以使 .war 本身可执行,但我想让“ .jar 中的 .war ”工作。
知道如何配置 .war 吗?