1

Maven に jetty-start のすべての依存関係を自動的にダウンロードさせようとしているので、これを実行します。

java start.jar etc/jetty.xml

しかし、私がこれを行うとき:

java start.jar --list-options

Maven ファイルに依存関係として手動で追加する必要があるいくつかの不足しているモジュールがあります。私はそれらを追加しようとしましたが、ダウンロードされたjarがその中にあるにもかかわらず、それservlet-apiが提供する適切なバージョンを見つけることに行き詰まりました。エラーは次のとおりです。javax.servlet.http.HttpServletResponsejetty-servletjavax/servlet/http/HttpServletResponse.class

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:457)
        at org.eclipse.jetty.start.Main.start(Main.java:602)
        at org.eclipse.jetty.start.Main.main(Main.java:82)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletResponse
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
        at java.lang.Class.getConstructor0(Class.java:2699)
        at java.lang.Class.newInstance0(Class.java:326)
        at java.lang.Class.newInstance(Class.java:308)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:333)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:291)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1203)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1138)
        ... 7 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletResponse
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 17 more

org.eclipse.jetty.aggregate:jetty-allパッケージを依存関係リストに追加しようとしましたが、その中のパッケージが によって検出されjava start.jar --list-optionsないため、機能しません。

役立つドキュメントのページがいくつかありますが、この質問には具体的に答えないでください。

4

4 に答える 4

5

あなたはそうしない。

jetty-start アーティファクトは、jetty ディストリビューションで使用するためのものです。jetty-start アーティファクトを使用する場合、依存関係の自動ダウンロードはありません。これは、ディストリビューションがローカルのディスク上にあり、サーバー起動用のクラスパスをまとめようとしているだけであると想定されているためです。

Maven では、ビルド中にテストまたはビルド目的で Web アプリケーションを開始する場合は、jetty-maven-plugin を使用します。そのプラグインを使用すると、追加の依存関係を要求する特定のことをしようとしない限り、必要な依存関係の大部分を取得できます。その場合、それらをプラグイン宣言のセクションに追加します。

乾杯!

于 2012-05-02T13:53:01.377 に答える
2

jetty-startやろうとしていることを行うにはとの両方が必要jetty-allですが、より具体的なアーティファクトのセットを使用することもできますjetty-all

クラスパス上の一連のアーティファクトでは使用できないためjava -jar、代わりにorg.eclipse.jetty.start.Main直接実行する必要があることに注意してください

例えば:

java -cp start.jar:jetty-all.jar org.eclipse.jetty.start.Main --list-options

必要な JAR (Maven の依存関係として取得される) を含むアセンブリを作成し、それらを指す開始スクリプトを追加することをお勧めします。

アセンブリ プラグインと Java サービス ラッパーを使用してJettyを実行する、より完全な例をここで見つけることができます。=マークアップ

于 2012-05-03T02:42:15.700 に答える
0

あなたの質問には答えられないかもしれませんが、main() メソッドで Jetty を起動する方法を次に示します。.war ファイルを含めてアセンブルされたアプリを作成し、ファイルシステムをスキャンして war を見つけ、ビルドされて配布 zip ファイルに含まれている war のコピーを使用して Jetty を起動します。

    String warLocation = locateWarFile();

    WebAppContext webapp = new WebAppContext();
    webapp.setWar(warLocation);

    webapp.setContextPath("/");

    webapp.setConfigurations(new Configuration[] {
            new WebInfConfiguration(),
            new EnvConfiguration(),
            new WebXmlConfiguration(),
    });

    // launch Jetty's web server and serve requests..
    Server server = new Server();
    Connector connector=new SelectChannelConnector();
    connector.setPort(Integer.getInteger("jetty.port",8080));
    server.setConnectors(new Connector[]{connector});
    server.setHandler(webapp);
    server.start();

記録のために、私のmavenの依存関係:

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-util</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-naming</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-plus</artifactId>
    </dependency>
于 2012-05-03T02:48:55.270 に答える
-1

次の POM ファイルは、Jetty を使用してApache Solr Web アプリケーションをダウンロードして実行するように構成されています。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myspotontheweb</groupId>
    <artifactId>solr</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr</artifactId>
            <version>3.6.0</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-velocity</artifactId>
            <version>3.6.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.3.v20120416</version>
                <configuration>
                    <systemProperties>
                        <systemProperty>
                            <name>solr.solr.home</name>
                            <value>${basedir}/src/main/solr/home</value>
                        </systemProperty>
                        <systemProperty>
                            <name>solr.data.dir</name>
                            <value>${project.build.directory}/solr/data</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>run-exploded</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

アプリケーションは次のように Maven から起動されます。

mvn compile

完全を期すために

Solrには追加の構成ファイルが必要です。詳しくはドコをご覧ください。

$ tree
.
|-- pom.xml
`-- src
    `-- main
        `-- solr
            `-- home
                `-- conf
                    |-- admin-extra.html
                    |-- elevate.xml
                    |-- mapping-FoldToASCII.txt
                    |-- mapping-ISOLatin1Accent.txt
                    |-- protwords.txt
                    |-- schema.xml
                    |-- scripts.conf
                    |-- solrconfig.xml
                    |-- spellings.txt
                    |-- stopwords_en.txt
                    |-- stopwords.txt
                    `-- synonyms.txt
于 2012-05-02T21:29:00.753 に答える