【问题标题】:Create Java class from WSDL从 WSDL 创建 Java 类
【发布时间】:2013-01-31 13:08:15
【问题描述】:

我正在尝试使用 maven cxf-codegen-plugin 从 WSDL 创建一个 Java 类,但是当我尝试这样做时,它只显示一个错误并且没有生成类。

我不明白为什么会出现这个错误,我的 pom 文件看起来还不错。

我的pom.xml 看起来像

 <dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.2.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>2.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-hc</artifactId>
        <version>2.7.3</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>2.5.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>2.7.3</version>

            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/resources/CurrentTimeService.wsdl</wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaIncludes>
                            <include>jaxb/try/*.xsd</include>
                        </schemaIncludes>
                        <episodeFile>${project.build.directory}/generated-sources/xjc/META-INF/jaxb-try.episode</episodeFile>
                    </configuration>
                    <id>jaxb-generate-try</id>
                </execution>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaIncludes>
                            <include>jaxb/try/*.xsd</include>
                        </schemaIncludes>
                        <episodeFile>${project.build.directory}/generated-sources/xjc/META-INF/jaxb-try.episode</episodeFile>
                        <generatePackage>q1.q2</generatePackage>
                    </configuration>
                    <id>jaxb-generate-try_1</id>
                </execution>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaIncludes>
                            <include>jaxb/try2/*.xsd</include>
                        </schemaIncludes>
                        <episodeFile>${project.build.directory}/generated-sources/xjc/META-INF/jaxb-try2.episode</episodeFile>
                    </configuration>
                    <id>jaxb-generate-try2</id>
                </execution>
            </executions>
            <configuration>
                <catalog>src/main/resources/jaxb/catalog.xml</catalog>
                <catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
                <forceRegenerate>true</forceRegenerate>
                <generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
                <verbose>true</verbose>
            </configuration>
        </plugin>
    </plugins>
</build>

当我使用 Maven 构建项目时,我看到以下错误

Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.3:wsdl2java (generate-sources) on project WebServicesTest: org.xml.sax.SAXParseException; systemId: jar:file:/C:/Users/user/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.2.6/jaxb-xjc-2.2.6.jar!/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd; lineNumber: 86; columnNumber: 48; src-resolve: Cannot resolve the name 'xjc:globalJavaType' to a(n) 'group' component. 

【问题讨论】:

  • 'xjc:globalJavaType' 似乎是 JAXB 问题,如果有帮助的话....
  • POM 看起来不太好在我看来...您有两个不同的 CXF 版本,2.7.3 和 2.5.1。另外,提供 WSDL 和 XSD 文件。
  • 两个 2.7.3 版本同样的问题

标签: java maven jaxb cxf wsdl2java


【解决方案1】:

看看这篇文章:

Cannot resolve the name 'xjc:globalJavaType' in jaxb-xjc-2.2.5-2.jar

您的本地 Maven 存储库的路径中可能包含非拉丁字符。尝试更改您的 settings.xml 以将其设置为仅包含拉丁字符的其他目录,看看是否有帮助。

【讨论】:

  • 谢谢,我会尝试更改我的仓库位置
  • 太好了,在 maven 本地存储库中更改为拉丁字符有帮助!谢谢!
  • 没问题,很高兴能帮上忙! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-23
  • 1970-01-01
相关资源
最近更新 更多