Java

Warning: Bootstrap classpath not set in conjunction…


Java or JDKs in particular provide a way of writing your applications to work with older JVMs.

For example you can be using JDK8 for development but you also want to make sure that your code runs in an older Java 7 based JVM. This is done using the “-target” and “-source” switches sent to the Java compiler javac.

So if you want to compile your app using JDK8  but also want to ensure that it works in Java7 you would do something like this.

javac -target 1.7 -source 1.7

Now this will make sure that your application source is not using any Java8 specific language features. For example if your code had used Lambda Expressions the compilation will fail now since they were introduced in Java 8 and are not available in Java 7.

But the problem is although the compiler can check for language features it does not (and most likely cannot) check for the usage of newer API classes introduced in the new Java platform.

So in our example here, if the application code tries to use the new JDK8 specific Date Time API classes, compilation will not fail even though you sent in “target 1.7” and “source 1.7” to the compiler!

And this is why the Java compiler warns you and suggests to set the “bootstrap classpath” to the older JDK specified in your “target” and “source” switches. This ensures that you will not use classes introduced in the the newer JDK.

javac -Xbootclasspath:/path/to/jdk7/rt.jar -target 1.7 -source 1.7

Now if your application code tries to use classes that were introduced in the newer JDK compilation will fail!

Advertisements

One thought on “Warning: Bootstrap classpath not set in conjunction…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s