How to change NetBeans Java Project Runtime?

How can I change the Projects Runtime Platform? (standard NetBeans [8.1] Java Project [Java Application])

Details:

  • using Ubuntu with NetBeans 8.1
  • I have installed JDK 1.6, JDK 1.7 + JDK 1.8
  • My projects platform is Java 6.
  • My systems default Java is Java 7.
  • NetBeans-IDE was started with Java 8.

When I run the project via the IDE (Run project), the Project-Platform is used (which is Java 6).

I cannot change the Runtime Platform! It's always: Project Platform

I tried to Manage Platforms..., but I still can't change the value of the Runtime Platform-ComboBox.

EDIT: As I wrote in the comments, I don't want to change the Project-Platform. The project should be compiled with Java 6 but run with Java 8 (when click on Run project).

What I want is: Project-Platform = Java 6 (used to compile), Runtime-Platform = Java 8 (used to run).

Answers


How can I change the Projects Runtime Platform?

Unfortunately you can't. As you point out, its value can only be Project Platform. Of course that invites the question "What is the point of even having that Runtime Platform field?".

I suspect that it may have been (unwisely) added to the GUI so that at some time in the future it will be possible to actually select a different JDK to run against. There is an open Bug Report for this: Bug 186747 - Can't Build and Run with Different Java Versions.

It's also worth noting that the Help documentation for the Run screen does not mention that Runtime Platform field. My own view is that the field should be removed until it serves a useful purpose.

What I want is: Project-Platform = Java 6 (used to compile), Runtime-Platform = Java 8 (used to run).

Unfortunately that can't be done, as shown by the open bug. The best you can do right now is:

  • Create platforms for JDK 6 and JDK 8 in NetBeans.
  • Set the Java Platform to JDK 1.6 on the Libraries screen, and set the Source/Binary Format to JDK 6 on the Sources screen, then build to verify that no invalid APIs are being used.
  • Switch the Java Platform to 1.8 on the Libraries screen to run your 1.6 code under 1.8.

I realize that you don't want to do that, but unfortunately there's no silver bullet in the current release of NetBeans (8.2).

An alternative approach would be to build and run using only JDK 8, but include the Animal Sniffer Maven plugin "for checking projects against the signatures of an API", to verify that your 1.6 code was not using illegal APIs. But of course that's only viable for Maven projects.


Please look at Netbeans Project Setup - Setting the Target JDK in a Project

You just have to change the Runtime Platform at the Libraries option, that's all.


Need Your Help

ipad rotation in iphone project

objective-c ios rotation orientation

I've created a project that is targeted just for iPhone (for now) and I chose supported orientation only Portrait. On iPhone it works great, but when I launch my project on iPad my application is

SSRS 2008 Reporting Services on SQL Server 2005

sql-server-2005 sql-server-2008 ssrs-2008

I know that the only stupid question is the one that you don't ask ... but even so this could be borderline :)