I have seen the compile options like discussed in Which JDK's distributions can run `javac -source 1.6 -target 1.5`?. I understand the individual options for source and target. I don't understand why source version is higher that the target version. Compiling the code for older targets makes sense. But in that case, why dont we just use -source of the oldest target we want to be able to run on
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Be sure to also set bootclasspath to ensure your program will work on older VMs.
From the
javac
documentation:JDK1.8 will no longer support -source and -target less than 1.6
Peter Tseng does mention a lot of key points to remember during compilation. As a matter of fact even I faced a similar issue sometime back and want to share the root causes of many issues.
I had a source code which had to compiled & make it compatible (-source & -target) Java '1.8'. The code itself had
java.sql.*
packageAfter certain changes I ended up with a code which had equal amount of JUnit test cases to run. Eventually I bumped into a
java.lang.VerifyError
. I was shocked when I understood that such error happens when I compile and run the code in the different libraries/environment(Which was not the case).What I almost missed was that, for honoring the fact that the tests had to run in an isolated environment, the Junit & its test cases where executed in a seperate forked VM
This obviously will be spanned as a separate process and act as a standalone application in execution. Even though the IDE spans both processes synchronously, the JVM's are pretty much isolated.
After Java 1.7, Oracle has introduced a stricter verification and changed the class format a bit -- to contain a stack map, used to verify that code is correct. The exception I had seen was because some method doesn't have a valid stack map. I eventually tried including lot of JVM options to tweak the setting, but in vain.
nothing worked. The only work around was to include
In Java 1.7 to allow only nominal byte code verification. Since this was taken off in Java 1.8, the only option was to use
Java is backwards compatible. You use the -source option to specify the java version used for compilation and you use the -target option to specify the lowest java version to support. eg. If I specify a target of 1.4, then my program will not be able to run on java 1.3 or lower. see the following javac documentation for more info. especially the section on Cross-Compilation Options