使用Maven进行增量Java编译(就像Eclipse一样) [英] Incremental java compile with maven (like Eclipse does)

查看:276
本文介绍了使用Maven进行增量Java编译(就像Eclipse一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用maven来构建存在未解决的编译问题的项目.

I want to use maven to build projects in which there are unresolved compilation problems.

主要目的是使用某种存根为包含编译错误的类打包和部署或运行​​应用程序,就像我了解Eclipse一样(感谢

The main purpose is package and deploy or run aplications using some kind of stubs for classes that contains compilation errors, like I understand that Eclipse does (thanks to JDT Core).

我在使用非Javac编译器以使用Eclipse编译器.认为应该设置一些参数来修改编译器/生成器,因为我正在阅读

I configurate maven java compiler plugin following Apache Maven documentation at Using Non-Javac compiler to use Eclipse compiler. Thinking that maybe should set some arguments to modify the compiler/builder behaivor I was reading Help Eclipse - Compiling Java code but I don't realize which compiler/builder option or combination of these does the trick.

到目前为止,Maven Java编译器插件的下一个配置使用eclipse编译器进行编译,并将应用程序(包括生成的.class(jvm字节码))打包为仅适用于没有编译错误的Java类.要获得这种行为,只需使用eclipse编译器(请参见CompilerId和依赖项)并设置failOnError=false.

So far, the next configuration of the maven java compiler plugins compile using the eclipse compiler and package the application including generated .class (jvm bytecode) only for java classes without compilation errors. To get this behaivor it just require use the eclipse compiler (see compilerId and the dependency) and set 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>

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

With this configuration I could run java application as long as the execution doesn't use classes not included for compilation errors (because the stubs aren't generated) but on a Java EE container, the classloading will faild so the application can never be deployed.

我对此表示感谢.

推荐答案

只为分享解决方案,那一刻,我只是将plexus-compiler-eclipse替换为tycho-compiler-jdt以获得欲望表现.

Just for share the solution, at that moment I just replace the plexus-compiler-eclipse with tycho-compiler-jdt to get the desire behaivor.

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

The proceedOnError parameter indicates that it must keep compiling in spite of errors, dumping class files with problem methods or problem types how to deal with the compilation errors.

下一步是最终的配置示例.

Next is the final configuration sample.

<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常见问题解答中有更多插件配置示例. 可能的编译器参数

There is more plugin configuration examples in the Tycho FAQ. And the possible compiler arguments are described in section Using the batch compiler of the Java development user guide (Eclipse Help site).

这篇关于使用Maven进行增量Java编译(就像Eclipse一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆