Использование Maven 3.0.3 для создания веб-службы с использованием JAXB (2.2.4-1) и CXF 2.4.2 завершается сбоем со следующей ошибкой:
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, которая не может быть аргументом метода.Это означает, что проблема заключается в поиске @XMLElement из пути загрузки JDK вместо того, чтобы сначала находить его в списке зависимостей, прежде чем искать в классах JDK.
Исходные файлы прекрасно работают в Eclipse, где, по-видимому,поставить зависимости перед классами JDK.
Я пытался использовать compilerArguments
и bootclasspath
или -Xbootclasspath/p:
в файле pom.xml, чтобы получить файл jax jaxb-api перед классами jdk, нони одна из них, похоже, не включает его в параметры командной строки при сборке с mvn -X clean compile
.Я также пытался изменить используемую версию maven-compiler-plugin, но из -X
она не изменилась.
Я создал урезанный проект, чтобы продемонстрировать ошибку.Вам нужно только первые два файла для репликации.Другие файлы включены в качестве рабочего примера, предполагая, что сборка работает с использованием веб-службы с использованием автономного веб-службы Jetty и Spring.
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();
}
}
}