gpt4 book ai didi

java - 使用 maven 进行增量 java 编译(就像 Eclipse 那样)

转载 作者:行者123 更新时间:2023-12-02 05:45:45 48 4
gpt4 key购买 nike

我想使用maven来构建存在 Unresolved 编译问题的项目。

主要目的是使用某种包含编译错误的类 stub 来打包和部署或运行​​应用程序,就像我了解 Eclipse 所做的那样(感谢 JDT Core )。

我按照 Apache Maven 文档配置 maven java 编译器插件 Using Non-Javac compiler使用Eclipse编译器。认为也许应该设置一些参数来修改我正在阅读的编译器/构建器行为 Help Eclipse - Compiling Java code但我不知道哪个编译器/构建器选项或它们的组合可以实现这一点。

到目前为止,maven java 编译器插件的下一个配置是使用 eclipse 编译器进行编译,并打包应用程序,包括生成的 .class(jvm 字节码),仅针对 java 类,没有编译错误。要获得此行为,只需使用 Eclipse 编译器(请参阅编译器 ID 和依赖项)并设置 failOnError=false

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<failOnError>false</failOnError>
<compilerArguments>
<org.eclipse.jdt.core.compiler.problem.fatalOptionalError>disabled</org.eclipse.jdt.core.compiler.problem.fatalOptionalError>
<org.eclipse.jdt.core.compiler.problem.forbiddenReference>ignore</org.eclipse.jdt.core.compiler.problem.forbiddenReference>
</compilerArguments>
</configuration>

<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>

使用此配置,只要执行不使用因编译错误而未包含的类(因为未生成 stub ),我就可以运行 java 应用程序,但在 Java EE 容器上,类加载将失败,因此应用程序可以永远不会被部署。

非常感谢您对此提供的任何帮助。

最佳答案

只是为了分享解决方案,当时我只是将 plexus-compiler-eclipse 替换为 tycho-compiler-jdt 以获得所需的行为。

proceedOnError参数表示尽管有错误,它仍必须继续编译,转储带有问题方法或问题类型的类文件如何处理编译错误。

接下来是最终的配置示例。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>jdt</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<failOnError>false</failOnError>
<compilerArguments>
<proceedOnError/>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>0.22.0</version>
</dependency>
</dependencies>
</plugin>

Tycho FAQ中有更多插件配置示例。可能的编译器参数Using the batch compiler 节中描述。 Java 开发用户指南(Eclipse 帮助站点)。

关于java - 使用 maven 进行增量 java 编译(就像 Eclipse 那样),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088623/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com