开发者

Eclipse builder incompatible with m2Eclipse and Maven

I'm seeing an issue where a given source file built by Maven produces a class file that is different than the o开发者_Go百科ne built by Eclipse.

The Eclipse builder is optimising away the following method:

public SomeClass clone() {
    SomeClass clone = (SomeClass) super.clone();
    return clone;
}

This method is obviously unnecessary but I don't have the option to change the source because it is generated.

Which builder is Eclipse using to compile these classes? I'm using the m2Eclipse plugin which I thought just invoked Maven to perform the build. Why is it that Eclipse then thinks it needs to perform another build with a different builder? Can I disable this Eclipse builder or configure it to prevent optimisation?

  • Eclipse version: 3.7
  • m2Eclipse version: 1.0.100.20110804-1717 (configured to use external Maven)
  • Maven version: 2.2.1

Update

I found an Eclipse bug report that describes what is going on. To clarify, its not actually the Eclipse compiler that is removing anything, it is just not introducing a synthetic 'bridge' method that the standard JDK compiler introduces. The bug report is marked as Resolved- Won't Fix.

I still haven't found a way to prevent the Eclipse builder from running after the Maven builder has run. But our fix is to modify the code generator to add an explicit serialVersionUID to the generated code.


You could try disabling Java Builder if configured for the project. You can check this by clicking on Builders tab in Project -> Properties.

From Eclipse help...

The Java builder builds Java programs using its own compiler (the Eclipse Compiler for Java) that implements the Java Language Specification.


I don't have Eclipse 3.7, but I expect that these things haven't changed since 3.6 . If you open Properties -> Builder on your project you should see that the Maven Builder comes last, or at least after the Java Builder. This means that when the Maven Builder sees your Java source files they are already compiled. By the way, the external Maven you configured is only used when you perform Run as -> and not when building with Maven.

All this is to say that what you see is likely do to the fact that when you compile from within Eclipse the internal Java compiler is used, while when you run Maven from the command line I expect that a JDK compiler is used, depending on what you have installed. I don't think there's anything you can do to change this state of things. One thing you could try is to ensure that their behaviour is as close as possible by specifying in your POM which Java version to be compliant to by adding something like

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.2</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

To your build section.

I have to say that I expected that the Java compiler was not allowed to remove public methods from classes, even if they are useless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜