【问题标题】:Unable to create java classes using codehaus.mojo jaxb2-maven-plugin无法使用 codehaus.mojo jaxb2-maven-plugin 创建 java 类
【发布时间】:2017-08-18 22:54:51
【问题描述】:

我有一个基于 Spring 的 Web 应用程序,我试图在其中使用 SOAP 服务。我为此使用 jaxb2-maven-plugin(org.codehaus.mojo)。但是,我看到了一个空的 jaxb2 文件夹,该文件夹在 target 下,我没有看到其中的任何 java 类。我已将 wsdl 正确放置在资源文件夹本身之下。

下面是在 pom.xml 中创建的插件配置

    <build>
        <finalName>${project.artifactId}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java/com/xyz/rap/service/impl/wsdl</directory>
                <targetPath>wsdl</targetPath>
            </resource>
            <resource>
                <directory>src/main/config</directory>
                <targetPath>config</targetPath>
            </resource>
        </resources>
        <plugins>
        <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- Package to store the generated file -->
                    <packageName>com.xxx.gen.retail.abc</packageName>
                    <!-- Treat the input as WSDL -->
                    <wsdl>true</wsdl>
                    <!-- Input is not XML schema -->
                    <xmlschema>false</xmlschema>
                    <!-- The location of the WSDL file -->
                    <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
                    <!-- The WSDL file that you saved earlier -->
                    <schemaFiles>gene.wsdl</schemaFiles>
                    <!-- Don't clear output directory on each run -->
                    <clearOutputDir>false</clearOutputDir>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- or whatever version you use -->
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

下面是我运行"maven install"时的日志

  [INFO] Building rap-web Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
**[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc) @ rap-web ---
[INFO] Generating source...
[WARNING] No encoding specified; default platform encoding will be used for generated sources.
[INFO] parsing a schema...
[INFO] compiling a schema...
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 15 resources
[INFO] Copying 3 resources to wsdl
[INFO] Copying 1 resource to config
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ rap-web ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 50 source files to C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\target\classes**
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ rap-web ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ rap-web ---

它说在日志中解析和编译模式,但我没有看到在日志中创建了任何 java 类,我看到一个空的 jaxb2 文件夹和另一个空的生成源文件夹被创建。请参考下图:

【问题讨论】:

    标签: java maven soap wsdl jaxb2-maven-plugin


    【解决方案1】:

    jaxb2-maven-plugin 将默认创建类到target/generated-sources/jaxb。如果您仍然没有将类放入目标文件夹,那么如果您使用的是 Eclipse,则可以将此文件夹添加到您的项目构建路径中:右键单击项目并选择“构建路径 > 使用源文件夹。

    然后你需要运行mvn clean install 它将清理或删除目标文件夹并重新生成所有内容。

    【讨论】:

    • 我试过了,但它没有在目标/生成源中创建任何 jaxb 文件夹。我怀疑问题是否出在 WSDL 本身。但是我可以使用 wsimport 生成存根,但不能使用 jaxb2-maven-plugin。
    【解决方案2】:

    试试 codehaus 2.2 版。请记住,您需要稍微更改您的 xml,因为 1.x 和 2.x 之间存在差异。

    话虽如此,我想告诉您我遇到了类似的问题。但这可能是由其他原因引起的。我正在使用 IntelliJ,它在 /target/generated-sources/ 下生成空的 jaxb 文件夹。

    <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                        <execution>
                            <id>xjc</id>
                            <goals>
                                <goal>xjc</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <sources>
                            <source>/src/main/resources/xsd/</source>
                        </sources>
                        <outputDirectory>${project.basedir}/target/generated-sources/jaxb</outputDirectory>
                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多