I was recently stung by some code making it through our deployment cycle without throwing any compile errors when it should have (we thought)...
The code in question being using the new static method Integer.compare
which is since Java 1.7.
The server environment is run on Java 1.6. While our development environments have Java 1.7 installed.
Our assumption was that setting the project preferences to JavaSE-1.6 compliance would at least give us compile warnings on the code in question, however no warning or error is visible in eclipse.
Project > properties > java compiler > JDK Compliance > Use compliance from execution environment 'JavaSE-1.6' on the java build path
Secondarily to that, we use maven to compile the final deployment. The pom is clearly directed to comply with the 1.6 compiler:
<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>
<optimize>true</optimize>
</configuration>
</plugin>
However the maven build runs successfully with the problem code.
How can I tell both maven and eclipse to fail when code will not work in an earlier Jvm than it is being compiled by?
Thanks, Paul.
Use the maven animal sniffer plugin to tell you when you use APIs that aren't backward compatible. I'm also told that Java 1.7 has a feature for this, but I have no personal experience with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With