226

I have the older NetBeans 6.7, NetBeans 6.9, and NetBeans 7.0, which used to run on jdk1.6.0_21 and jdk1.6.0_25. Now I've removed those JDKs and only have jdk1.6.0_26 and jdk1.7.0 left, but I still want to keep the older versions of NetBeans, but now when I run them, I get this message:

"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.6.0_25
Do you want to try to use default version?"

I tried to find where it's looking for the "jdk1.6.0_25", and updated a few configuration files in "C:\Program Files (x86)\NetBeans 6.7" and "C:\Users\USER.nbi\registry.xml", and yet the message keeps coming. Where and what do I need to change to point it to C:\Program Files (x86)\Java\jdk1.6.0_26?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Frank
  • 30,590
  • 58
  • 161
  • 244

9 Answers9

398

Thanks to Kasun Gajasinghe's tip, I found the solution in the "suggested" link. Update the following file (replace 7.x with your NetBeans version):

C:\Program Files\NetBeans 7.x\etc\netbeans.conf

Change the following line to point it where your Java installation is:

netbeans_jdkhome="C:\Program Files\Java\jdk1.7xxxxx"

You may need administrator privileges to edit netbeans.conf.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Frank
  • 30,590
  • 58
  • 161
  • 244
  • I ran into this problem after replacing OpenJDK with Oracle's Java for Android development on Ubuntu 13.04. The file is in `/usr/local/netbeans-7.3/etc/netbeans.conf` And my adjusted line looks like this: `netbeans_jdkhome="/usr/java/jdk1.7.0_21"` – asciimo Jun 01 '13 at 22:31
  • This has always worked for me but somehow recently it did not and I couldn't track down any explanation other than yours. By accident I thought to edit the file as Administrator and that did have the right effect. Somehow Windows 7 Enterprise and Windows 8 Pro are maintaining two versions of this file for me (see http://superuser.com/q/680110/47313) – Core Nov 24 '13 at 20:18
  • 2
    @asciimo For completion, you can even customize the properties on a per-user basis by writing a `netbeans.conf` under `~/.netbeans/version/etc` that overrides the `/usr/local...` properties file. (I assume `/usr/local/netbeans-7.3/etc` is your distro installation folder--I'm developing with a manual installed version in customized folder and cannot be 100% sure--.) – Alberto Apr 07 '14 at 14:23
  • 4
    NB: As of Netbeans 8 there is also a netbeans.conf in `C:\Users\You\AppData\Roaming\NetBeans\8.0\etc\netbeans.conf`. – OldCurmudgeon Jul 17 '14 at 08:47
  • @OldCurmudgeon In my case the file you mentioned and the etc dir didn't exist, but netbeans_jdkhome worked, when I created the file manually. Thanks! – Veelkoov Aug 19 '14 at 13:16
  • Works perfectly with current NetBeans 8.0.1! – Andreas Oct 10 '14 at 04:03
  • 2
    As noted in the comments in that file, you can comment out the line to let the launcher decide which version to use. This normally manages to automatically pick the most recent version. – Bob Feb 17 '15 at 22:24
  • 3
    @OldCurmudgeon Not for me there isn't. – BadHorsie Feb 24 '15 at 10:36
  • 1
    Heed the suggestion that Administrator privileges are needed to edit netbeans.conf, at least under Windows 7. I tried editing the file _without_ Administrator privileges and while it appeared to work, apparently Windows actually saved the updated file as a separate copy that was only visible to me via Windows Explorer. When NetBeans ran, it read the _original_ file, which still referenced the old JDK. What bizarre and confusing behavior on the part of Windows. – Kevin Rahe Apr 23 '15 at 20:16
  • solution still valid for netbeans 8.1 i've mistakenly pointed jdk home to /usr during the installation changed the pointed file part to /usr/lib/jvm/java on my fedora box and it has java capabilities again! – Sombriks Aug 14 '16 at 16:52
70

Go to Tools* → Java Platforms. There, click on Add Platform and point it to C:\Program Files (x86)\Java\jdk1.6.0_25. You can either set the another JDK version or remove existing versions.

Another solution suggested on the Oracle (Sun) site is,

netbeans.exe --jdkhome "C:\Program Files\jdk1.6.0_20"

I tried this on 6.9.1. You may change the JDK per project as well. You need to set the available JDKs via the Java Platforms dialog. Then, go to RunSet Project ConfigurationCustomize. After that, in the opened dialog box, go to menu BuildCompile. Set the version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kasun Gajasinghe
  • 2,735
  • 1
  • 21
  • 30
33

For those not using Windows, the file to change is netbeans-8.0/etc/netbeans.conf.

And the line(s) to change is:

netbeans_jdkhome="/usr/lib/jvm/java-8-oracle"

Comment out the old value and insert the new value.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Walt Corey
  • 718
  • 7
  • 12
7

As a further useful solution for those of you on Windows 7 and above - if you use

cd "C:\Program Files\Java"
mklink /D jdk8 jdk1.8.0_25

you get a symbolic link folder that can be adjusted whenever a new JDK comes out.

All you need to do then is set your

netbeans_jdkhome="C:\Program Files\Java\jdk8"

(in both locations for NetBeans 8) and you never have to edit the configuration again. Just tweak the symlink each time your JDK is updated.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
6

I had this message too because today I decided to relocate my different JDK in the same directory. I have decided to uninstall all through the program manager of Windows. After that, of course I had the message below.

"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.7.0_60. Do you want to try to use the default version?"

A new install of the JDK does not resolve the problem. OK, you can configure that in menu ToolsJava platforms, but in my case I had to fix my netbeans.conf file.

I had the line below:

netbeans_jdkhome="C:\Program Files\Java\jdk1.7.0_60"

And I replaced it by:

netbeans_jdkhome="C:\devtools\Java\jdk1.8.0_25"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
grome55
  • 653
  • 1
  • 8
  • 12
  • 1
    You probably want to just comment out that line. In that case, Netbeans will search and find the latest version on startup. – Duncan Mar 22 '16 at 14:52
5

It does not exactly answer your question, but to get around the problem,

  1. you can either create a .cmd file with following content:

    start netbeans --jdkhome c:\path\to\jdk

  2. or in the shortcut of Netbeans set the above option.

kdabir
  • 9,623
  • 3
  • 43
  • 45
4

Where you already have a project in NetBeans and you wish to change the compiler (e.g. from 1.7 to 1.) then you would need to also change the Java source compiler for that project.

Right-click on the project and choose Properties as outlined below:

Java Project Properties

Then check that the project has the necessary source circled below:

Project Source Compiler

Then check that the Java compiler is correct for the project:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

All the other answers have described how to explicitly specify the location of the Java platform, which is fine if you really want to use a specific version of Java. However, if you just want to use the most up-to-date version of the JDK, and you have that installed in a "normal" place for your operating system, then the best solution is to not specify a JDK location. Instead, let the NetBeans launcher search for the JDK every time you start it up.

To do this, do not specify jdkhome on the command line, and comment out the line setting netbeans_jdkhome variable in any netbeans.conf files. (See other answers for where to look for these files.)

If you do this, when you install a new version of Java, your NetBeans installation will automagically use it. In most cases, that's probably exactly what you want.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Duncan
  • 507
  • 3
  • 14
1

In Windows, open cmd.

Go to the directory where your NetBeans file downloaded.

Then run the below command. The JDK path may be different from the path I mentioned.

netbeans-8.2-windows.exe --javahome "C:\Program Files\Java\jdk-9.0.1"
Dilraj Singh
  • 951
  • 10
  • 12