javac source and target options

后端 未结 4 997
北海茫月
北海茫月 2020-11-27 19:04

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

4条回答
  •  渐次进展
    2020-11-27 19:44

    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

    1. Lot of Trademark symbol hence I ended up in unrecognized characters(I had to tweak the IntelliJ Idea's encoding settings)
    2. Lot of changes to java.sql.* package
    3. Usage of lot of third-party libraries. Spare me the horror of explaining the difficulty debugging there and blah blah blah.

    After 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

    
    

提交回复
热议问题