6

I want to set the default Java Platform which is used to build my projects in NetBeans 8.2 (netbeans_jdkhome).

Prior versions allowed me to do that. See this answer.

The only problem is that I want to set this platform to be 1.7 (instead of current 1.8), but NetBeans 8.2 requires to run on 1.8, so I cannot have 1.7 as the default Java Platform.

Is there a way to override it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Groben
  • 1,374
  • 2
  • 10
  • 29
  • 10
    This is part of [a meta question](https://meta.stackoverflow.com/questions/411963). – Peter Mortensen Oct 04 '21 at 11:53
  • Does this answer your question? [Can NetBeans 7.4 have JDK 1.6 as a default platform?](https://stackoverflow.com/questions/19633215/can-netbeans-7-4-have-jdk-1-6-as-a-default-platform) - Exact same issue but wanting to use JDK 1.6 instead of 1.7 when Netbeans 7.4 required 1.7. You've been mis-using `netbeans_jdkhome`, – Nick is tired Oct 04 '21 at 16:56
  • 2
    @Nick: No, they've been using it correctly. `netbeans_jdkhome` configures *both* the new project default JDK version and the JDK version Netbeans itself runs on, because Netbeans uses the JDK it's running on as the default JDK for new projects. See https://docs.oracle.com/netbeans/nb82/netbeans/NBDAG/create_japps.htm#NBDAG465 – user2357112 Oct 04 '21 at 17:01
  • 3
    Unfortunately, the lack of separate "Netbeans JDK" and "default new project JDK" settings means there probably isn't a way to do what the questioner is looking for. – user2357112 Oct 04 '21 at 17:03
  • @user2357112supportsMonica Just because it _also_ sets the default project JDK version doesn't mean that's what it's intended to be used for, although I do get your point. – Nick is tired Oct 04 '21 at 17:03
  • 2
    You correctly state in your answer that there is no solution to your question, but there is a workaround: [1] Set your default JDK to JDK7 in **netbeans conf**. This makes JDK 7 your default JDK for both NetBeans and projects. [2] Override that setting whenever you start NetBeans 8.2 using **netbeans --jdkhome {JDK8 path}**. This allows you to run NB 8.2 on JDK 8, but JDK7 will still be the default for all your existing and future projects. – skomisa Oct 04 '21 at 17:52
  • 2
    Of course there will be a problem with that approach if you fail to provide the **--jdkhome** parameter when you start NetBeans 8.2, because it will try (unsuccessfully) to run on JDK 7. But while this is a less than perfect solution, it does address your question. – skomisa Oct 04 '21 at 17:58
  • 4
    @skomisa That set of steps sounds like it'd make an excellent _answer_, rather than being left to gather dust here in the comments where it may be hidden or deleted sometime down the line. – zcoop98 Oct 04 '21 at 21:22
  • @zcoop98 I don't post answers without supporting evidence, and creating an environment to prove that suggestion would take non-trivial time and effort. Besides, I don't view it as a proper solution, and the accepted answer posted nearly five years ago by the OP is the correct one. But if you feel inclined, you are welcome to post it as an answer yourself. I'll be happy to upvote as long as there is supporting evidence to show it really works. – skomisa Oct 08 '21 at 15:30

3 Answers3

14

You can get your default JDK by: menu ToolsJava Platforms. There you can add all your JDKs and watch their bibs.

If you want to change the default one, you need to go the path C:\Program Files\NetBeans 8.2\etc and you need to change the netbeans.conf file.

In line 57 (in mine) you see something like this:

netbeans_jdkhome="C:\Program Files\Java\jdk1.8.0_66"

Change the path to your wanted JDK and you’re finished.

Here is a longer description.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LenglBoy
  • 1,451
  • 1
  • 10
  • 24
  • 2
    This is exactly what I said was not possible with netbeans 8.2 – Groben Dec 01 '16 at 12:05
  • Same situation but it worked. Netbeans running all new projects default java 1.8 and old ones with 1.7 and itself with 1.8, too. – LenglBoy Dec 01 '16 at 14:11
  • 8
    If you put 1.7 as your netbeans_jdkhome, netbeans doesn't start, it requires 1.8 – Groben Dec 02 '16 at 08:30
  • 1
    Excellent. Just to add that if you have write access privilege denied, then close NetBeans, right-click the netbeans.conf and choose properties, then choose the security tab and choose all users full access. That is of course if you are using Windows-based platform. –  Aug 13 '18 at 17:54
  • 7
    `netbeans_jdkhome` is the JDK Netbeans itself runs on. Setting it to a version Netbeans can't run on won't work. Judging by LenglBoy's comments, it looks like they changed it from 1.7 to 1.8, which is the exact opposite of what the question is about. The question is looking for a way to set the default JDK for projects to 1.7. – user2357112 Oct 04 '21 at 16:39
  • 6
    Perhaps this is getting upvotes from people who had a different problem (about getting Netbeans itself to run), and a search engine landed them here? If I understand correctly, it doesn't answer the question at all. (Apparently not even if your system default JDK is 1.7; setting this would still make it the default JDK for new projects according to comments on the question.) – Peter Cordes Oct 04 '21 at 21:21
14

For now, it appears there isn't any way to override it. Here is NetBeans Help about the Java Platform Manager:

Use to register different versions of the Java Development Kit (JDK) and other Java tools that your programs depend on. The dialog box lists all of your registered JDKs in the left pane and lists the JDK that the IDE is running on as the Default Platform.

So I'll have to change platform for each project, because NetBeans 8.2 can not run with JDK 1.7 (so I can't set it as the default platform).

There is a recent plugin that allows to right-click Maven projects to set the JDK (still cannot set it by default).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Groben
  • 1,374
  • 2
  • 10
  • 29
4

There is no Eclipse-like default option.

You can set the Java platform for every imported project. See Change JRE in a NetBeans project

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jovo Skorupan
  • 237
  • 2
  • 5