java - 如何在maven中做多个生成源代码的主类
问题描述
当我在一个模块中运行 mvn clean install 时,如何在 maven pom.xml 中执行此操作?
- 编译主要源代码
- 在编译的源代码中调用主类以生成另一个源代码
- 第 1 组和第 2 组并再次执行编译
- 在打包阶段,原始源代码和生成的源代码应该在 jar 中
解决方案
我尝试并有效的解决方案之一。基本上你在生成额外的java代码后强制再次调用maven编译器插件
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>generate-code</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>compile</classpathScope>
<mainClass>MyClassGenerator</mainClass>
<arguments>
<argument>${generated.code.dir}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>addtoSourceFolder</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<sources>
<source>${generated.code.dir}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>compile-generated-code</id>
<configuration>
<includes>**/*.java</includes>
</configuration>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
推荐阅读
- java - MS Word 阻止编辑受保护的文档,因为 word 说文档被另一位作者更改,而没有人编辑它
- apache-kafka - 使用 Reactor Kafka 发送事件似乎很慢
- java - Spring Boot Crud 存储库
- sql - 错误:SQLITE_RANGE:SELECT 语句中的列索引超出范围
- javascript - 获取 ReactJS 返回的数据
- events - 使用 Jdbc 驱动程序订阅 Firebird 事件以进行连接?
- netsuite - 我们如何使用 Suite 脚本模拟“下一个账单”按钮功能?
- python - 在 Keras 中一次上传一部分数据集
- ms-access - 生成包含期初和期末余额的 MS Access 报告
- android - 如何在重新启动后重新启动服务而不通过前台服务显示任何通知