我正在使用 cxf-xjc 生成 Web 服务工件,并尝试使用 build-helper 插件将它们添加到源中。当它在单个 Maven 项目中使用时,它可以正常工作,但是现在我已经进入了一个多模块项目,生成的类没有作为源包含在内。
类已正确生成,并且在生成类后正在执行 build-helper 插件。build-helper 的输出显示了类所在的正确源目录路径并显示“已添加”。
pom.xml
<!-- CXF -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<id>generate-xsd-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/java</sourceRoot>
<xsdOptions>
<xsdOption>
<!-- <bindingFile>src/main/resources/request.xjb</bindingFile> -->
<xsd>src/main/resources/request.xsd</xsd>
<packagename>${services.package}.package.request</packagename>
</xsdOption>
<xsdOption>
<!-- <bindingFile>src/main/resources/response.xjb</bindingFile> -->
<xsd>src/main/resources/response.xsd</xsd>
<packagename>${services.package}.package.response</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
<!-- Move generated to source -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
控制台截图
[INFO] --- **cxf-xjc-plugin:2.3.0:xsdtojava (generate-xsd-sources) @ aggregation-jaxrs-api** ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ aggregation-jaxrs-api ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ aggregation-jaxrs-api ---
[INFO] Compiling 55 source files to C:\workspace\aggregation-parent\aggregation-jaxrs-api\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ aggregation-jaxrs-api ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ aggregation-jaxrs-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ aggregation-jaxrs-api ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ aggregation-jaxrs-api ---
[INFO] Building jar: C:\workspace\aggregation-parent\aggregation-jaxrs-api\target\aggregation-jaxrs-api-1.0-SNAPSHOT.jar
[INFO]
**[INFO] --- build-helper-maven-plugin:1.12:add-source (add-source) @ aggregation-jaxrs-api ---
[INFO] Source directory: C:\workspace\aggregation-parent\aggregation-jaxrs-api\target\generated-sources\java added.**
在我将其移至模块之前,此配置运行良好。我已经更改为生成源和流程源阶段之间的构建助手阶段,但没有运气。我正在使用基于 Eclipse Neon 4.6.1 的 Spring Tool Suite 3.8。
谢谢