Dave Jarvis
Dave Jarvis

Reputation: 31161

Multiple Platforms, One JDK Installation

Background

Installed JDK v1.8.0_92 and NetBeans v8.0.2.

Problem

The project requires the Java Platform 1.7, as seen here:

NetBeans Project Properties

Question

Is it possible to use JDK 1.8 and set 1.7 as the target platform? If so, how?

Additional Details

Setting the target build (via Additional Compiler Options) does not affect the target platform, as seen here:

NetBeans Target Build

I am under the impression that I'll need to install both JDK 1.8 (required for PMD) and JDK 1.7 (required for the project).

Ideally, I'd like avoid multiple JDK installs on the same machine. I suspect that this isn't possible because functionality in the 1.7 platform might have been removed in 1.8 (e.g., deprecated methods).

Upvotes: 1

Views: 82

Answers (1)

radai
radai

Reputation: 24192

not only is it possible to install multiple JDKs on the same computer, it is what most developers in your situation end up doing. the only thing to be careful of is multiple JDKs on the path (and JAVA_HOME) at the same time (and obviously the JDK on the path should match the one in JAVA_HOME, most easily ensured by adding %JAVA_HOME%\bin to the path env var)

functionality in the 1.7 platform might have been removed in 1.8

JDKs are notoriously backwards compatible. there's stuff in there thats left in from Java 1 and will likely never be removed (to the detriment of some java devs, me included). some common (annoying) examples are Thread.stop(), weird values for serialVersionUid on some classes, the incomplete support for generics because of java 4 compatibility, the continued existence of the original Container classes and AWT, and much, much, more.

the bigger concern would actually be installing and using JDK 8 and targeting java 7 (by specifying -target, as you do in your screenshot). the risk here is that you'll accidentally import and something thats new to java 8, at which point jdk8 will gladly produce java7-compatible bytecode that would fail to find the class/method you used at runtime.

personally, on windows, what i do is just extract a bunch of JDKs somewhere (say c:\dev\tools\jdks) and configure different IDE projects to use different ones, as needed. i dont like having them "installed".

Upvotes: 2

Related Questions