I work on a Java program that should be compatibe with Java 5. I had @Override
annotations on implemented interface methods which is allowed in Java 6, but not in 5. I use a Java 6 SDK. Eclipse correctly gives error messages on the @Override
when I set it to 5.0 compliance. My Maven build, however, runs without even a warning, using the following settings in my POM:
我正在研究一個應該與Java 5兼容的Java程序。我對Java 6中允許的實現接口方法進行了@Override注釋,但是在5中沒有。我使用的是Java 6 SDK。當我將其設置為5.0合規性時,Eclipse正確地在@Override上提供錯誤消息。但是,我的Maven構建在我的POM中使用以下設置運行時甚至沒有警告:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Am I correct in expecting that this should actually make the build fail? Why doesn't it, and is there something I can do?
我是否正確期望這實際上會使構建失敗?為什么不呢,有什么我可以做的嗎?
This is actually a JDK problem, not a Maven problem. The @Override annotation is not failing with a -source 1.5 flag to to a 1.6 javac. Go ahead and try it. The only way to make it fail, is, unfortunately, to use a 1.5 javac.
這實際上是一個JDK問題,而不是Maven問題。 @Override注釋沒有使用-source 1.5標志失敗到1.6 javac。繼續嘗試。令人遺憾的是,讓它失敗的唯一方法是使用1.5 javac。
Sorry, HTH.
EDIT
I ran into this problem myself, and I also wondered if it's actually looking at the setting in the pom. Turning on debug output (-X I believe, was a while ago) will print the javac command line to the standard output, and you'll see that it is indeed using the -source 1.5 parameter.
編輯我自己遇到了這個問題,我也想知道它是否真的在看pom中的設置。打開調試輸出(-X我相信,不久前)會將javac命令行打印到標准輸出,你會發現它確實使用了-source 1.5參數。
As roe's answer says you need to use a 1.5 compiler because the JDK isn't doing its job quite right. It's worth pointing out that you can avoid messing about with paths etc. by tweaking the maven-compiler-plugin configuration to use a specific compiler:
正如roe的回答所說,你需要使用1.5編譯器,因為JDK沒有完全正確地完成它的工作。值得指出的是,你可以通過調整maven-compiler-plugin配置來使用特定的編譯器來避免弄亂路徑等:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_5_HOME}/bin/javac</executable>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
...
</plugins>
You can then specify the path to the compiler in your project or settings.xml
然后,您可以在項目或settings.xml中指定編譯器的路徑
<properties>
<JAVA_1_5_HOME>/path/to/1.5jdk</JAVA_1_5_HOME>
</properties>
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/07/28/7202014406f57e6124ed85a33f8a200d.html。