编译错误:执行javac失败,但无法解析错误

时间:2012-03-19 10:39:52

标签: java compilation hudson

当我启动像mvn clean compile这样的Hudson作业时,我遇到了跟​​随错误。

[INFO] Compiling 1541 source files to /users/applis/33g/ad33gwas/.hudson/jobs/sonar facade-commande/workspace/facade-commande/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
An exception has occurred in the compiler (1.5.0_12). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.AssertionError

你对这个问题有什么理由吗?

2 个答案:

答案 0 :(得分:4)

您遇到了编译器错误。目前尚不清楚它可能是哪个错误,但很有可能通过升级到更高版本的JDK来修复它。

(你显然正在运行java 1.5.0_u12,这很古老。最后一个免费提供的Java 1.5补丁版本是java 1.5.0_u22。这是最新的1.5版本(到1.5.0._u34)可用于订阅Java for Business的人。或者,您可以升级到Java 1.6或1.7。)

答案 1 :(得分:0)

我有好几次这个问题。你已经很幸运了,编译器甚至报告了一个错误,因为在我的情况下它没有报错,而Maven后来因为一些不可理解的错误而失败。

最终,我发现编译器没有很好地处理一些复杂的类型(类似<A extends MyObject<A1,A2>, A1 extends MyObject2<A2>, A2 extends MyObject3>)。更新JVM可能会解决您的问题,但随着代码的发展,也可能会再次遇到问题。似乎这些错误在JDK-7中已经消失,但我无法确定。

无论如何,一种解决方案是为你的代码使用备用编译器(比如tycho),你可以在你的pom.xml中这样做(在build - &gt; plugins或build - &gt; pluginManagement-- &GT;插件):

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${compiler.source}</source>
                    <target>${compiler.target}</target>
                    <encoding>${source.encoding}</encoding>
                    <fork>false</fork>
                    <compilerId>jdt</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.tycho</groupId>
                        <artifactId>tycho-compiler-jdt</artifactId>
                        <version>0.13.0</version>
                    </dependency>
                </dependencies>
            </plugin>

如果您使用的是Eclipse和M2E 1.0或更高版本,则会出现错误,但您可以通过将以下代码段添加到pom.xml中来解决此问题(在build - &gt; pluginManagement - &gt; plugins中) ):

            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-compiler-plugin</artifactId>
                                    <versionRange>[2.0,)</versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                        <goal>testCompile</goal>
                                    </goals>
                                    <parameters>
                                        <compilerId>jdt</compilerId>
                                    </parameters>
                                </pluginExecutionFilter>
                                <action>
                                    <configurator>
                                        <id>org.eclipse.m2e.jdt.javaConfigurator</id>
                                    </configurator>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>

相当丑陋并且已经向m2e开发人员报告了这个问题,但他们并不认为这是优先事项,所以你必须忍受它

相关问题