2

私はJavaで書かれたWebアプリケーションを持っています。

組み込みの jetty サーバーで統合テストを実行したいと考えています。

その目的のために、私はMavenプロジェクトを持っています(統合テストを実行するためだけに)。

デプロイには cargo-maven2-plugin を使用します。しかし、桟橋の起動中に次のメッセージが表示されます。

java.lang.ClassCastException: org.mortbay.jetty.webapp.WebInfConfiguration cannot be cast to org.mortbay.jetty.webapp.Configuration

完全なログ:

[beddedLocalContainer] Jetty 6.x Embedded starting...
2010-03-29 16:20:46.615::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
2010-03-29 16:20:46.715::INFO:  jetty-6.1.1rc1
2010-03-29 16:20:46.980::INFO:  Extract jar:file:/C:/Documents%20and%20Settings/Alpha/Local%20Settings/Temp/cargo/conf/cargocpc.war!/ to C:\DOCUME~1\Alpha\LOCALS~1\Temp\Jetty_0_0_0_0_8080_cargocpc.war__cargocpc__xflgf3\webapp
log4j:WARN No appenders could be found for logger (org.apache.jasper.compiler.JspRuntimeContext).
log4j:WARN Please initialize the log4j system properly.
2010-03-29 16:20:47.897::INFO:  Started SelectChannelConnector @ 0.0.0.0:8080
[beddedLocalContainer] Jetty 6.x Embedded started on port [8080]
[cargo:deployer]
[mbeddedLocalDeployer] Deploying [c:\maven-repo\myapp\2.1-SNAPSHOT\myapp-2.1-SNAPSHOT.war]
2010-03-29 16:20:51.711::WARN:  Failed startup of context org.mortbay.jetty.webapp.WebAppContext@132e910{/myapp,c:\maven-repo\myapp\2.1-SNAPSHOT\myapp-2.1-SNAPSHOT.war}
java.lang.ClassCastException: org.mortbay.jetty.webapp.WebInfConfiguration cannot be cast to org.mortbay.jetty.webapp.Configuration
        at org.mortbay.jetty.webapp.WebAppContext.loadConfigurations(WebAppContext.java:801)
        at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:403)
        at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
        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.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalContainer.addHandler(Jetty6xEmbeddedLocalContainer.java:294)
        at org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalDeployer.deployWebApp(Jetty6xEmbeddedLocalDeployer.java:77)
        at org.codehaus.cargo.container.jetty.internal.AbstractJettyEmbeddedLocalDeployer.deploy(AbstractJettyEmbeddedLocalDeployer.java:95)
        at org.codehaus.cargo.maven2.DeployerDeployMojo.performDeployerActionOnSingleDeployable(DeployerDeployMojo.java:79)
        at org.codehaus.cargo.maven2.AbstractDeployerMojo.performDeployerActionOnAllDeployables(AbstractDeployerMojo.java:104)
        at org.codehaus.cargo.maven2.AbstractDeployerMojo.doExecute(AbstractDeployerMojo.java:47)
        at org.codehaus.cargo.maven2.AbstractCargoMojo.execute(AbstractCargoMojo.java:255)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        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.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Maven 貨物設定:

<profile>
<id>container-cargo-jetty</id>
<properties>
    <skip.test.phase>true</skip.test.phase>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <wait>false</wait>
                <container>
                    <containerId>jetty6x</containerId>
                    <type>embedded</type>
                </container>
                <configuration>
                    <properties>
                        <cargo.servlet.port>8080</cargo.servlet.port>
                        <cargo.logging>medium</cargo.logging>
                    </properties>
                </configuration>
                <deployer>
                    <deployables>
                        <deployable>
                            <groupId>myapp</groupId>
                            <artifactId>myapp</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/myapp</context>
                            </properties>
                        </deployable>
                    </deployables>
                </deployer>
            </configuration>
            <executions>
                <execution>
                    <id>start-container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                        <goal>deployer-deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-container</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-embedded</artifactId>
                    <version>6.1.22</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

助けてthx

4

2 に答える 2

2

JETTY で「クラスローダー地獄」を扱っている可能性があります。JETTY インスタンスの親クラスローダーは、Web アプリケーションに使用されるものとは別のものであり、同一のクラスである必要がありますが、そうではありません。

JETTY 構成には、同じクラスローダーの使用を強制するいくつかのオプションがあり、統合テストに役立つ場合があります。

クラスローディング - JETTY

Jetty は、これら 3 つのオプションすべてを制御する構成オプションを提供します。メソッド org.mortbay.jetty.webapp.WebAppContext.setParentLoaderPriority(boolean) を使用すると、通常の Java 2 の動作を使用でき、可能であればすべてのクラスがシステム クラスパスからロードされます。これは、Web アプリケーションが使用するライブラリで、Web アプリケーションとシステム クラスパスの両方にあるクラスのロードに問題がある場合に非常に役立ちます。

Cargo で JETTY 設定にアクセスする方法はわかりませんが、通常の JETTY Maven プラグインでは次のようにします。

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.0.0.pre5</version>
    <configuration>
        <jettyConfig>${jetty.configs}</jettyConfig>
        <reload>manual</reload>
        <contextPath>/</contextPath>
        <webAppConfig>
            <parentLoaderPriority>true</parentLoaderPriority>

        </webAppConfig>
    </configuration>
</plugin>
于 2010-03-29T22:32:44.203 に答える
2

Cargo が使用する埋め込み Jetty のバージョンの指定はサポートされていません (これに関しては、古い未解決の問題があります。CARGO-571を参照してください)。実際、ログを見ると、jetty-6.1.1rc1 が使用されていることがわかります。

2010-03-29 16:20:46.715::INFO:  jetty-6.1.1rc1

したがって、最初に、プラグイン構成内の jetty 依存関係を削除しますClassCastException

しかし、依存関係が削除されると、別のあいまいなコモンズ ロギングの問題に直面しました。

Caused by: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy.  You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.

そして、その原因は次の部分にあるようです:

            <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>start</goal>
                    <goal>deployer-deploy</goal>
                </goals>
            </execution>

deploy-deploy正直なところ、なぜここでゴールと呼ぶのかわかりません。それがなければ、Cargo は宣言された を展開しdeployableます。したがって、IMO ではこの目標を指定する必要はありません。そして、それを削除した場合、例外はありません(そして2番目の「修正」)。

要約すると、次の構成が機能します。

<profile>
  <id>container-cargo-jetty</id>
  <properties>
    <skip.test.phase>true</skip.test.phase>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <wait>false</wait>
          <container>
            <containerId>jetty6x</containerId>
            <type>embedded</type>
          </container>
          <configuration>
           <properties>
             <cargo.servlet.port>8080</cargo.servlet.port>
             <cargo.logging>medium</cargo.logging>
            </properties>
          </configuration>
          <deployer>
            <deployables>
              <deployable>
                <groupId>myapp</groupId>
                <artifactId>myapp</artifactId>
                <type>war</type>
                <properties>
                  <context>/myapp</context>
                </properties>
              </deployable>
            </deployables>
          </deployer>
        </configuration>
        <executions>
          <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
于 2010-03-29T22:34:52.243 に答える