我已经设置了Arquillian(嵌入式GlassFish),用于测试一些涉及使用Web服务的功能。
当我运行测试时,我得到以下异常堆栈: http://pastebin.com/BU1rpaCr
查看StackTrace,实际错误似乎是这样的:
java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;
我认为通过正确修改pom.xml可以解决这个问题,但我还没弄清楚如何正确修改它。
这就是我在pom.xml中所拥有的:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<parent>
<groupId>xxx</groupId>
<artifactId>super-pom</artifactId>
<version>1.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.ws</groupId>
<artifactId>wsclient</artifactId>
<packaging>jar</packaging>
<name>xxx: WEBSERVICE CLIENT</name>
<!-- Replace with a detailed description of the project. -->
<description>
</description>
<version>1.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${wls.jdk.version}</source>
<target>${wls.jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.3.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-impl</artifactId>
<version>1.0.0.Alpha6</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jira.project.key>xxx</jira.project.key>
<vcs.module.path>https://svn.company.com/svn/zzz/yyy/trunk/xxx/parent/wsclient/</vcs.module.path>
<env>dev</env>
<wls.jdk.version>1.6</wls.jdk.version>
</properties>
<profile>
<id>arquillian-weld-ee-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.1.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<!-- Same error with and without this -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1-1</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arquillian-glassfish-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
它使用的是java 1.6。这可能是与此相关的一些东西(正如我从其他类似帖子中所理解的那样)。 我也是Arquillian的新人,但我已经设法用它做了一些工作测试,所以我认为不应该有太多错误。 (如果我退出ws-calls,这个测试类也会成功运行)
答案 0 :(得分:1)
这个看起来像是遇到了涉及嵌入式GlassFish的JAX-WS和JAXB API的问题。如果您使用的是Java 1.6,则需要将这些API用作endorsed libraries。
如果您想避免这种情况(可能是因为您在生产中使用了托管的GlassFish实例),那么我建议不要使用嵌入式GlassFish容器进行测试。您的项目POM会更简单。并且您在测试期间使用的技术堆栈将更加真实,因为API可以在正确的类加载器等中使用。
答案 1 :(得分:0)
在这种情况下,解决方案似乎使用了'背书'库。这必须通过使用Maven而不是手动将库复制到自动“认可”的位置来实现。
这个问题似乎有正确的答案: How to specify the JAXB version in maven-jaxb2-plugin?
我不得不做一个小修改。我用2.1。版本以使此正常(使用2.2时相同的错误)。
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.16</version>
<type>jar</type>
</artifactItem>
</artifactItems>