0
2014-02-24 10:15:42,121 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /NornLM/: java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils

mvn -X -P wildfly test这是来自( 有commons-io-1.4.jar)的输出片段

[DEBUG] boot(compact) classpath:  surefire-booter-2.16.jar  surefire-api-2.16.jar  test-classes  classes  junit-4.11.jar  hamcrest-core-1.3.jar  arquillian-junit-container-1.1.2.Final.jar  arquillian-junit-core-1.1.2.Final.jar  arquillian-test-api-1.1.2.Final.jar  arquillian-test-spi-1.1.2.Final.jar  arquillian-core-spi-1.1.2.Final.jar  arquillian-container-test-api-1.1.2.Final.jar  shrinkwrap-api-1.1.2.jar  arquillian-container-test-spi-1.1.2.Final.jar  arquillian-core-impl-base-1.1.2.Final.jar  arquillian-test-impl-base-1.1.2.Final.jar  arquillian-container-impl-base-1.1.2.Final.jar  arquillian-config-api-1.1.2.Final.jar  arquillian-config-impl-base-1.1.2.Final.jar  arquillian-container-test-impl-base-1.1.2.Final.jar  shrinkwrap-impl-base-1.1.2.jar  shrinkwrap-spi-1.1.2.jar  slf4j-api-1.7.6.jar  slf4j-simple-1.7.6.jar  commons-io-1.4.jar  activation-1.1.1.jar  cdi-api-1.1.jar  javax.inject-1.jar  jsr181-api-1.0-MR1.jar  javax.mail-1.5.1.jar  validation-api-1.1.0.Final.jar  hibernate-jpa-2.1-api-1.0.0.Final.jar  jboss-annotations-api_1.2_spec-1.0.0.Final.jar  jboss-batch-api_1.0_spec-1.0.0.Final.jar  jboss-ejb-api_3.2_spec-1.0.0.Final.jar  jboss-el-api_3.0_spec-1.0.0.Final.jar  jboss-concurrency-api_1.0_spec-1.0.0.Final.jar  jboss-jsf-api_2.2_spec-2.2.5.jar  jboss-interceptors-api_1.2_spec-1.0.0.Final.jar  jboss-json-api_1.0_spec-1.0.0.Final.jar  jboss-j2eemgmt-api_1.1_spec-1.0.1.Final.jar  jboss-connector-api_1.7_spec-1.0.0.Final.jar  jboss-rmi-api_1.0_spec-1.0.4.Final.jar  jboss-jacc-api_1.5_spec-1.0.0.Final.jar  jboss-jaspi-api_1.1_spec-1.0.0.Final.jar  jboss-jms-api_2.0_spec-1.0.0.Final.jar  jboss-servlet-api_3.1_spec-1.0.0.Final.jar  jboss-jsp-api_2.3_spec-1.0.0.Final.jar  jboss-jstl-api_1.2_spec-1.0.4.Final.jar  jboss-transaction-api_1.2_spec-1.0.0.Final.jar  jaxrs-api-3.0.6.Final.jar  jboss-websocket-api_1.0_spec-1.0.0.Final.jar  jboss-jaxb-api_2.2_spec-1.0.4.Final.jar  jboss-saaj-api_1.3_spec-1.0.3.Final.jar  jboss-jaxws-api_2.2_spec-2.0.2.Final.jar  wildfly-arquillian-container-managed-8.0.0.Final.jar  wildfly-arquillian-common-8.0.0.Final.jar  arquillian-testenricher-cdi-1.1.2.Final.jar  arquillian-testenricher-ejb-1.1.2.Final.jar  arquillian-testenricher-initialcontext-1.1.2.Final.jar  arquillian-testenricher-osgi-2.1.0.CR2.jar  arquillian-testenricher-resource-1.1.2.Final.jar  wildfly-arquillian-testenricher-msc-8.0.0.Final.jar  wildfly-server-8.0.0.Final.jar  wildfly-controller-8.0.0.Final.jar  wildfly-core-security-8.0.0.Final.jar  staxmapper-1.1.0.Final.jar  wildfly-domain-http-interface-8.0.0.Final.jar  wildfly-domain-management-8.0.0.Final.jar  wildfly-deployment-repository-8.0.0.Final.jar  wildfly-patching-8.0.0.Final.jar  wildfly-cli-8.0.0.Final.jar  aesh-0.33.11.jar  jansi-1.9.jar  picketbox-4.0.20.Final.jar  jconsole.jar  wildfly-platform-mbean-8.0.0.Final.jar  wildfly-process-controller-8.0.0.Final.jar  wildfly-remoting-8.0.0.Final.jar  wildfly-io-8.0.0.Final.jar  wildfly-network-8.0.0.Final.jar  wildfly-version-8.0.0.Final.jar  jandex-1.1.0.Final.jar  jboss-invocation-1.2.1.Final.jar  jboss-logmanager-1.5.2.Final.jar  jboss-modules-1.3.0.Final.jar  jboss-stdio-1.0.2.GA.jar  jboss-vfs-3.2.2.Final.jar  undertow-core-1.0.0.Final.jar  jboss-msc-1.2.0.Final.jar  wildfly-controller-client-8.0.0.Final.jar  wildfly-protocol-8.0.0.Final.jar  jboss-dmr-1.2.0.Final.jar  jboss-threads-2.1.1.Final.jar  wildfly-jmx-8.0.0.Final.jar  jboss-common-core-2.2.22.GA.jar  wildfly-naming-8.0.0.Final.jar  jboss-remote-naming-2.0.0.Final.jar  jboss-ejb-client-2.0.0.Final.jar  org.osgi.core-5.0.0.jar  wildfly-arquillian-protocol-jmx-8.0.0.Final.jar  wildfly-security-manager-1.0.0.Final.jar  arquillian-protocol-jmx-1.1.2.Final.jar  jbosgi-metadata-3.0.1.Final.jar  xnio-api-3.2.0.Final.jar  xnio-nio-3.2.0.Final.jar  jboss-logging-3.1.4.GA.jar  jboss-marshalling-1.4.3.Final.jar  jboss-marshalling-river-1.4.3.Final.jar  jboss-remoting-4.0.0.Final.jar  remoting-jmx-2.0.0.Final.jar  jboss-sasl-1.0.4.Final.jar  arquillian-core-api-1.1.2.Final.jar  wildfly-build-config-8.0.0.Final.jar  arquillian-protocol-servlet-1.1.2.Final.jar  arquillian-container-spi-1.1.2.Final.jar  shrinkwrap-descriptors-api-base-2.0.0-alpha-3.jar  shrinkwrap-descriptors-spi-2.0.0-alpha-3.jar  resteasy-client-3.0.6.Final.jar  resteasy-jaxrs-3.0.6.Final.jar  scannotation-1.0.3.jar  javassist-3.12.1.GA.jar  jboss-annotations-api_1.1_spec-1.0.1.Final.jar  httpclient-4.2.1.jar  httpcore-4.2.1.jar  commons-logging-1.1.1.jar  commons-codec-1.6.jar  jcip-annotations-1.0.jar  surefire-junit4-2.16.jar
Forking command line: /bin/sh -c cd /home/xenoterracide/dev/java/lm && /home/xenoterracide/dev/java/jdk1.8.0/jre/bin/java -jar /home/xenoterracide/dev/java/lm/target/surefire/surefirebooter3880936643245584750.jar /home/xenoterracide/dev/java/lm/target/surefire/surefire6230151177352487731tmp /home/xenoterracide/dev/java/lm/target/surefire/surefire_03011675312761419534tmp

这就是我添加的内容pom.xml

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
        <scope>compile</scope> <!-- tried removing this line -->
    </dependency>

为什么这不足以使我的代码正常工作?

4

1 回答 1

0

我猜它必须在存档中,因为它不是作为 Wildfly 的一部分运送的,而我使用的其他所有东西都在其中。

我做的第一件事,可能无关紧要,正确的是我没有在我的问题中提出的 BOM 的顺序

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-bom</artifactId>
            <version>2.0.2</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap</groupId>
            <artifactId>shrinkwrap-bom</artifactId>
            <version>1.2.1</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.1.2.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

然后我确保所有的部门都是正确的

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
        <type>jar</type>
    </dependency>

并为 maven 添加了 shrinkwrap 解析器

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-api-maven</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
    </dependency>

然后将其添加到我的战争中

public static WebArchive testWar() {
    File[] libs
            = Maven.resolver().loadPomFromFile( "pom.xml" )
            .resolve( "commons-io:commons-io" )
            .withTransitivity()
            .asFile();

    System.out.println( "libs = " + Arrays.toString( libs ) );

    return ShrinkWrap.create( WebArchive.class )
            .setWebXML( new File( "src/main/webapp/WEB-INF/web.xml" ) )
            .addAsWebInfResource( new File( "src/main/webapp/WEB-INF/jboss-web.xml" ) )
            .addAsWebInfResource( EmptyAsset.INSTANCE, "beans.xml" )
            .addPackages( false, Filters.exclude( ".*Test.*" ), getCorePackages() )
            .addAsLibraries( libs );
}
于 2014-02-24T18:56:48.750 回答