使用Maven 3.0.3構建使用JAXB(2.2.4-1)和CXF 2.4.2的Web服務失敗,並顯示以下錯誤:帶註釋的JAXB 2.2.4-1 Web服務的Maven構建失敗,出現JDK 1.6
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project cxfmaventest: Compilation failure
/Users/ksuda/Documents/workspace/cxfmaventest/src/main/java/cxfmaventest/CXFMavenTest.java:[18,83] annotation type not applicable to this kind of declaration
失敗的行包含@XMLElement(required = true)
,允許JAXB在方法參數上。 JDK 1.6包含不允許在方法參數上的@XMLElement的先前版本。這意味着這是一個路徑問題,它從JDK的bootclasspath中查找@XMLElement,而不是在查看JDK類之前先在依賴項列表中找到它。
源代碼在Eclipse中很好地構建,它似乎將依賴關係放在JDK類之前。
我已經在pom.xml皮卡的JDK類前JAXB的API jar文件使用compilerArguments
,要麼bootclasspath
或-Xbootclasspath/p:
嘗試過,但似乎都不當我建立與mvn -X clean compile
使用命令行選項,包括它。我也試着改變它使用的maven-compiler-plugin版本,但是從-X
它沒有改變它。
我創建了一個精簡的項目來演示錯誤。您應該只需要前兩個文件進行復制。其他文件包含在工作示例中,假設構建工作使用獨立碼頭Web服務和Spring公開Web服務。
CXFMavenText.java:
package cxfmaventest;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@WebService(targetNamespace = "http:/cxfmaventest/", name = "CXFMavenTest")
@Service("cxfmaventestws")
public class CXFMavenTest extends SpringBeanAutowiringSupport {
@WebMethod
@WebResult(name = "test")
public String getHelloWorld(@WebParam(mode = WebParam.Mode.IN, name = "mode") @XmlElement(required = true) String mode) throws Exception {
return "Hello World";
}
}
的pom.xml:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cxfmaventest</groupId>
<artifactId>cxfmaventest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>cxfmaventest</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.4-1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>7.4.2.v20110526</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin></artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin></artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
applicationContet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<context:component-scan base-package="cxfmaventest" />
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="ws" implementor="#cxfmaventestws" address="/">
<jaxws:features>
<!-- <bean class="org.apache.cxf.feature.LoggingFeature"/> -->
</jaxws:features>
</jaxws:endpoint>
<context:annotation-config />
</beans>
WEB-INF/web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>CXFMavenTest</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
</web-app>
CXFMavenTextStandalone.java:
package cxfmaventest;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class CXFMavenTestStandalone {
public static void main(String[] args) {
try {
String root = ".";
String port = "8080";
for (int x = 0; x < args.length; ++x) {
if (args[x].startsWith("-root=")) {
root = args[x].substring(6);
} else if (args[x].startsWith("-port=")) {
port = args[x].substring(6);
} else {
System.out.println("Arguments:");
System.out.println(" -root=<path> - Set the root path for the webapp files. Defaults to the current directory.");
System.out.println(" -port=<port#> - Set the port number to run the server on. Defaults to port 8080.");
System.exit(1);
}
}
Server server = new Server(Integer.parseInt(port));
WebAppContext context = new WebAppContext();
context.setDescriptor(root + "/WEB-INF/web.xml");
context.setResourceBase(root);
context.setContextPath("/cxfmaventest");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}