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をどのように構成する必要があるか考えていますか?