maven - 无法使用Maven执行wsdl2java

标签 maven grails wsdl2java

我想用Maven执行wsdl2java,但是出现以下构建失败:

    [INFO] --- maven-dependency-plugin:2.1:copy (default) @ mogopay ---
[INFO] Configured Artifact: javax.xml.bind:jaxb-api:2.2:jar
[INFO] Configured Artifact: javax.xml.ws:jaxws-api:2.2:jar
[INFO] Copying jaxb-api-2.2.jar to c:\Users\EBIZNEXT\git\mogopay-core\mogopay\target\endorsed\jaxb-api-2.2.jar
[INFO] Copying jaxws-api-2.2.jar to c:\Users\EBIZNEXT\git\mogopay-core\mogopay\target\endorsed\jaxws-api-2.2.jar
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (copy-tomcat-resources) @ mogopay ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] --- cxf-codegen-plugin:2.4.2:wsdl2java (CXF Payline) @ mogopay ---
[INFO] Running wsdl2java in fork mode...
[INFO] Building jar: C:\Users\EBIZNEXT\AppData\Local\Temp\cxf-tmp-679212\cxf-codegen5225275003143491559.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:30.351s
[INFO] Finished at: Tue Jan 22 18:28:57 CET 2013
[INFO] Final Memory: 14M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.4.2:wsdl2java (CXF Payline) on project mogopay:
[ERROR] Exit code: 1 - Exception in thread "main" org.apache.cxf.tools.common.ToolException: java.lang.reflect.UndeclaredThrowableException
[ERROR] at
   ...
[ERROR] Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()
[ERROR] at java.lang.Class.getDeclaredMethod(Class.java:1954)
[ERROR] at com.sun.codemodel.TypedAnnotationWriter.invoke(TypedAnnotationWriter.java:107)
[ERROR] ... 27 more
[ERROR]
[ERROR] Command line was: "c:\Program Files\Java\jdk1.7.0\jre\bin\java.exe" -Djava.endorsed.dirs=c:\Users\EBIZNEXT\git\mogopay-core\mogopay\target/endorsed -jar
 C:\Users\EBIZNEXT\AppData\Local\Temp\cxf-tmp-679212\cxf-codegen5225275003143491559.jar C:\Users\EBIZNEXT\AppData\Local\Temp\cxf-tmp-679212\cxf-w2j3628405823287
641812args

该项目基于grails 2.0.3构建。看来问题出在Jaxb,因为grails中的当前版本使用jaxb-api-2.1,而项目需要jaxb 2.2。我已经更新了pom,从以下答案中可以看出:Set Java Compliance Level in CXF wsdl2java以及此处:Example 7 - Using JAXB/JAX-WS 2.2 with Java 6。但是当我执行maven命令:mvn clean install时,出现了上面的错误。

这是我的pom(我删除了不重要的部分):
<pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArguments>
                        <endorseddirs>${project.build.directory}/endorsed</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <forkMode>once</forkMode>
                    <argLine>-Djava.endorsed.dirs=${project.build.directory}/endorsed</argLine>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

         <plugins>
             ...
             <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax.xml.bind</groupId>
                                <artifactId>jaxb-api</artifactId>
                                <version>2.2</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>javax.xml.ws</groupId>
                                <artifactId>jaxws-api</artifactId>
                                <version>2.2</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/endorsed</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin> 
                ...
               <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
                <fork>once</fork>
                <additionalJvmArgs>-Djava.endorsed.dirs=${project.build.directory}/endorsed</additionalJvmArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                    <version>2.8.1</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                    <version>2.2</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>2.2</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>CXF Payline</id>
                    <phase>process-resources</phase>
                    <configuration>
                        <sourceRoot>${basedir}/src/java</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/java/wsdl/Payline_DirectPaymentAPI.wsdl</wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>                
         </plugins>

任何建议将不胜感激

最佳答案

Java 7已经包含了jaxb 2.2(您可以看到here精确地为2.2.4-1),因此您无需向该 Artifact 添加任何依赖项。如果此 Artifact 与grails 2.0.3依赖项冲突,请尝试从grails依赖项中排除jaxb,也许grails对jaxb 2.2感到满意。

这应该是评论,但我已经开始使用过滤javascript的代理,因此无法使用评论功能。对不起,我的英语去!

关于maven - 无法使用Maven执行wsdl2java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464917/

相关文章:

java - Spring Boot - NoClassDefFoundError : ch/qos/logback/classic/Level

java - 文件上传完整性检查

maven-2 - CXF maven 插件在错误的目录中生成类

java - 无法从 WSDL 生成 stub /java 骨架

java - SonarQune 提示从 wsdl 文件生成的 _equalsCalc 变量不是 transient 的或可序列化的

java - 获取NoSuchMethodError : org. hamcrest.core.StringContains.containsStringIgnoringCase

eclipse - Maven 多模块项目中的 Autowiring 依赖项

grails - Grails-应用程序和本地插件之间的引用

grails - 无法为Grails 2.2.3安装可搜索的0.6.5

java - 谁负责更新 App Engine 的 Maven 存储库?其他人可以这样做吗?