tabolz.blogg.se

Compiling java using javac
Compiling java using javac









Okay, so what's up? Well the fact is that although we specified the source and target levels to conform to Java 8, the compilation is still done against the classes in JDK 9! Issues don't surface often because of this, as Java is generally developed in a backward compatible way. The output it not what we'd expect: Exception in thread "main" : ()Ljava/nio/ByteBuffer Īt Compile8Test.main(Compile8Test.java:6) Let's run it! path/to/java8/bin/java Compile8Test It compiles fine, we do receive a warning though: warning: bootstrap class path not set in conjunction with -source 1.8 When you typed javac, that part is called compilation, which prepares a Java. Let's see how it can affect our compilation output: path/to/jdk9/bin/javac Compile8Test.java -source 8 -target 8 Luckily, for compiling and running Java programs, the actual commands are. You (or your underlying build system) may've kept using the -source and -target parameters although the -release was just introduced. If you're like us, you may've just upgraded your Java version without putting much thought into how it may affect your compilation process. The -release option was introduced in JDK 9.

compiling java using javac

This was the correct example, showcasing how you should cross-compile Java for older versions. The output is nothing out of the ordinary: Success path/to/jdk9/bin/javac Compile8Test.java -release 8Īs a test, we should run it on Java 8: path/to/java8/bin/java Compile8Test Let's compile it for Java 8, using the -release option. It's quite simple and should properly work on Java 8, 9, or later. In the following, we'll compile a simple class to Java 8, using javac from JDK 9. If you've been cross-compiling Java code for older releases, and were using the -source and -target javac parameters, you may experience unexpected errors when your app is deployed.

compiling java using javac

Beware of the -source and -target javac parameters











Compiling java using javac