I was recently hit by some code that did this through our deployment cycle, without throwing any compilation errors when it should (we thought) ...
The code in question uses the new static method Integer.compare
, which is found with Java 1.7.
The server environment runs on Java 1.6. Although Java 1.7 is installed in our development environments.
Our assumption was that setting project preferences to match JavaSE-1.6 would at least give us a compilation of warnings for the code in question, but eclipse doesnโt show a warning or error.
Project> properties> java compiler> JDK Compliance> Use compliance from the 'JavaSE-1.6' runtime in the java build path
Secondly, we use maven to compile the final deployment. Obviously, pom will obey compiler 1.6:
<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 succeeds with the problem code.
How can I say that both maven and eclipse fail if the code does not work in an earlier Jvm than it compiles?
Thanks, Paul.
source share