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.
1
  • recheck please both: java -version , javac -version Jan 29, 2020 at 15:43

12 Answers 12

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\..."
13
  • 2
    I'm using Linux. However /usr/local/netbeans-8.0.2/etc/netbeans.conf contains the line netbeans_jdkhome="/root/Downloads/jdk1.8.0_40". Thanks, Mar 14, 2015 at 18:14
  • No. It is not working. That line was there immediately after the installation. Thanks, Mar 14, 2015 at 18:34
  • Are you sure the directory still exists and contain bin directory with JDK binaries? Mar 14, 2015 at 18:36
  • 1
    Yes. It still exists plus I tried changing that line to netbeans_jdkhome="/usr/bin/java". It made no difference. I still get the same error message. Thanks, Mar 14, 2015 at 18:39
  • How do you execute NetBeans. Does the user have rights to read from that directory? Mar 14, 2015 at 18:51
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
3
  • This was the only solution that worked for me, using Netbeans on OS X.
    – Manachi
    Jul 5, 2017 at 1:23
  • Works for ubuntu 18.04 too. Good job mate
    – bigwolk
    Sep 27, 2018 at 20:15
  • For editing via notepad you can use command gedit netbeans.conf from console, or open this file with explorer as root May 20, 2019 at 18:54
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.

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

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”.

1

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

1
  • 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 ). Jan 29, 2020 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"

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

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.

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.

0

Just "suffered" on Windows and latest Netbeans 19, no way to use something in the PATH variable...

To solve, I've added to the shortcut in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Apache NetBeans" an argument like below:

--jdkhome "C:\Program Files\Java\jdk-11.0.7"
-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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.