5

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

4

2 に答える 2

4

私は特定のアプリのために2009-10年にこれでたくさん遊んだ。

jar:私が見つけた問題は、jar内にwarが埋め込まれている場合、URIがwarファイルにアクセスしようとするデフォルトのURIハンドラーで機能しないものになる可能性があることです。

私が見つけた解決策はたくさんあります:

  1. 一時ディレクトリにwarファイルを抽出/展開するようにjettyに指示します

  2. 独自のURIハンドラーを実装します(これは興味深い演習でしたが、コードを自分でサポートする必要がある場合は、それを行うことはお勧めしません)

  3. WARファイルを実行可能なWARファイルにします。たとえば、Jenkinsで使用されるのと同じタイプのトリックです。これを行うには、jettyサーバークラスとメインクラスをwarファイルでオーバーレイします。次に、jettyをwarファイルとしてjarファイル自体にポイントします。Jettyは、ファイル名がで終わらないことを気にしません.war

3つすべてがJetty7で私のために働いた。状況は同じままであると思う。

結局、私はオプション3を選択しました。これは最も単純なものとして機能し、ユーザーシステムに一時ファイルを残さず、起動が最も速くなります。

于 2012-11-17T20:46:51.623 に答える
0

jarファイルをjarファイルに入れて試してみましたが、jettyは、warファイルを唯一のエントリとしてリストしたディレクトリを提供してくれたようです。奇妙なことに気づきました...そこで何か間違ったことをしたかどうかはわかりません...

これまでのところ、jarファイル内のディレクトリでwarファイルを分解することはうまくいくように思われることがわかりました。私は後でいくつかの奇妙なことを発掘するかもしれませんが、私がそうするまで、私はそれに固執します。

于 2017-12-19T06:39:20.873 に答える