30

I have just installed Netbeans 8.0.2 on CentOS 6.5.

When I try to run it, I get the message

Cannot find java. Please use the --jdkhome switch

I have /usr/share/java-1.7.0 so I typed

/usr/local/netbeans-8.0.2/bin/netbeans --jdkhome /usr/share/java-1.7.0

and still got

Cannot find java. Please use the --jdkhome switch

I also have /root/Downloads/jdk1.8.0_40 which allowed me to install Netbeans. However, when I type

/usr/local/netbeans-8.0.2/bin/netbeans --jdkhome /root/Downloads/jdk1.8.0_40

I still get

Cannot find java. Please use the --jdkhome switch

I tried

whereis java

and got

java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz

However

/usr/local/netbeans-8.0.2/bin/netbeans --jdkhome /usr/bin/java

still produces

Cannot find java. Please use the --jdkhome switch.
OtagoHarbour
  • 3,969
  • 6
  • 43
  • 81

11 Answers11

43

I do recommend you to change the configuration of JDK used by NetBeans in netbeans.conf config file:

netbeans_jdkhome="C:\Program Files\Java\..."
Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40
29
  1. Go to the netbeans installation directory
  2. Find configuration file [installation-directory]/etc/netbeans.conf
  3. towards the end find the line netbeans_jdkhome=...
  4. comment this line line using '#'
  5. now run netbeans. launcher will find jdk itself (from $JDK_HOME/$JAVA_HOME) environment variable

example:

sudo vim /usr/local/netbeans-8.2/etc/netbeans.conf
dave_k_smith
  • 655
  • 1
  • 7
  • 22
Maruf Hamidi
  • 391
  • 3
  • 5
3

ATTENTION MAC OS USERS


First, please remember that in a Mac computer the netbeans.conf file is stored at

/Applications/NetBeans/NetBeans 8.2.app/Contents/Resources/NetBeans/etc/netbeans.conf

(if you had used the default installation package.)

Then, also remember that the directory you MUST use on either "netbeans_jdkhome" or "--jdkhome" it's NOT the /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/ but the following one:

/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home //<-- Please, notice the /Contents/Home at the end. That's the "trick"!

Note: of course, you must change the versions for both NetBeans and JDK you're using.

Almir Campos
  • 2,833
  • 1
  • 30
  • 26
2

Check the setting in your user config /home/username/.netbeans/version/etc/netbeans.conf

I had the problem where I was specifying the location globally, but my user setting was overriding the global setting.

CentOS 7/Netbeans 8.1

ntm
  • 83
  • 1
  • 6
1

NetBeans 8.2 - Cannot locate java installation in specified jdkhome?

Answer: Edit the netbeans.conf file.

Close NetBeans, start Notepad or another text editor as Administrator. Right click on the Notepad application and choose "Run as administrator" and then open netbeans.conf with it. Change netbeans_jdkhome=”C:\Program Files...whatever”.

dirk
  • 61
  • 4
1

Try Java SE Runtime Environment 8. It fixed it for me.

Sus20200
  • 337
  • 3
  • 13
  • Netbeans searches JDK HOME by `javac` location (not `java` location), so in my case `java` and `javac` location were differ by error, then it can not find correct JDK HOME location (see source netbeans/platform/lib/nbexec ). – user1742529 Jan 29 '20 at 15:40
0

With the Netbeans 10, commenting out the netbeans_jdkhome setting in .../etc/netbeans.conf doesn't do the job anymore. It is necessary to specify the right directory depending of 32/64 bitness.

E.g. for 64 bit application: netbeans_jdkhome="C:\Program Files\AdoptOpenJDK\jdk8u202-b08"

Franc Drobnič
  • 985
  • 10
  • 14
0

If like me, you got that message after installing jenv, simply add netbeans_jdkhome="$JAVA_HOME" to your [netbeans-installation-directory]/etc/netbeans.conf file

Captain A
  • 191
  • 1
  • 2
  • 11
0

In my case, I had installed *ahem* OpenJDK, but the bin folder was full of symlinks to the bundled JRE and the actual JDK was nowhere to be found.

When I see a directory structure with bin and jre subdirectories I expect this to be the JDK installation, because JRE installations on Windows looked different. But in this case it was the JRE installation as found out by apt search. After installing openjdk-8-jre the simlinks were replaced and the directory structure otherwise stayed the same.

Mark Jeronimus
  • 9,278
  • 3
  • 37
  • 50
0

Just add the following lines to the end of .profile file inside your home directory and then logout and login or reboot:

export JAVA_HOME=/path/to/jdk
export PATH="$JAVA_HOME/bin:$PATH"

in which /path/to/jdk points to your JDK installation folder. For exapmple /snap/openjdk/1163/jdk.

Dante
  • 611
  • 1
  • 7
  • 21
-1

What worked for me is:

  • make sure java path is available:
$ which java
/usr/bin/java
  • then in etc/netbeans.conf make sure netbeans_jdkhome is commented out
  • in Finder go to /bin/ click on netbeans (terminal icon)

You would expect ./netbeans --jdkhome=/usr/bin/java to work, but it doesn't for some reason.

f1vlad
  • 227
  • 3
  • 12