9

Java is properly installed in my Ubuntu 12.04 and the PATH variable is set in the .bashrc file.

The command java -version gives an expected output.

But when I try to start Eclipse, it complains as JDK not found.

enter image description here

siva636
  • 16,109
  • 23
  • 97
  • 135

8 Answers8

11

You might need to edit your eclipse.ini file and mention the path there. Read this for more details.

EDIT:

 -vm
/opt/sun-jdk-1.6.0.02/bin/java

This is how your vm argument should be in the .ini file. If not,change it. Be careful about the path though. Generally Java is installed in /opt,but check once on your system.

Also, look at this question as well.

Community
  • 1
  • 1
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
6

It looks to me like you have set the PATH environment in your shell, but you are launching Eclipse using some menu item or shortcut, and the context is using a different PATH.

One option is to change the eclipse.ini file as other answers say.

Another option is to try to figure out why Eclipse is being launched with a different PATH to the one in your command path. (The "fix" might simply be to logout and login again to make the launcher pick up the updated PATH setting. Or launcher may be picking up the incorrect PATH setting from somewhere else.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • You seem to be correct, but how can I set the PATH the way Eclipse expects? (I try to launch Eclipse by clicking eclipse executable) – siva636 May 27 '12 at 14:49
  • 1
    @DUKE - I don't run Ubuntu. Try logging out / in again. FWIW, I always launch Eclipse from the commmand line to avoid problems like this. But I'm a bit of a luddite ... :-) – Stephen C May 27 '12 at 14:51
  • Of course, launching from terminal works! (but launching by clicking the eclipse executable dosen't work). Thank you Stephen C – siva636 May 27 '12 at 14:57
  • @DUKE - have you logged out / in again ... yet? – Stephen C May 27 '12 at 15:03
  • I tried log out / in, but this does not seem to be giving any effect. – siva636 May 27 '12 at 15:05
  • 1
    I think this Q&A may address your problem: http://askubuntu.com/questions/103741/which-path-variable-is-valid-for-launchers – Stephen C May 27 '12 at 15:37
  • 1
    `.bashrc` is the wrong file to put PATH in. `.bashrc` is only executed for non-login shells (eg new terminal windows you open). Put the PATH variable in `.bash_profile` instead. This is executed for login shells (The GUI is a child process of your login shell). – Dunes May 27 '12 at 15:39
  • @Stephen C - Launch by clicking works if the PATH is defined in .profile file, thanks again. – siva636 May 27 '12 at 17:01
5

Java in Ubuntu is usually located at /usr/lib/jvm/<your_java_version>, but ubuntu usually creates a symlink to the current version of java at /usr/lib/jvm/java-7-sun. The symlink may or may not exist depending on how you installed java on your machine, now that it is no longer available at the repos.

Navigate to /usr/lib/jvm/ and type the ls command to find the appropriate folder java is located in. Once you have the location nailed down, look for a file named libjvm.so.

In my machine, the -vm arg looks like this:

-vm
/usr/lib/jvm/java-6-sun/jre/lib/amd64/server/libjvm.so

Make sure the path is in a new line below -vm or it won't work.

Jeshurun
  • 22,940
  • 6
  • 79
  • 92
1

You can explicitely tell your eclipse session which jdk/jre you want it to start with adding the following in your eclipse.ini:

-vm home/..../jre/bin/javaw.exe
emilan
  • 12,825
  • 11
  • 32
  • 37
0

Install eclipse via the package manager and you shouldn't have this problem.

You've installed eclipse manually in your home directory and eclipse is trying to find a jre where it was installed, but you probably didn't download a version of eclipse that comes with its own jdk. As such it needs a little more help to work.

Like I said above, delete your current installation and install via the package manager.

Dunes
  • 37,291
  • 7
  • 81
  • 97
0

Follow below step to define path variable available for all launcher for manually installed JDK

Step:

1-

 cd /etc/

2-

sudo vim ~/.profile

3- Add below codes in your step2 open file

  PATH="$HOME/bin:$HOME/.local/bin:/usr/lib:$PATH"

  JAVA_HOME="/usr/lib/jvm/jdk1.7.0_79"

  export JAVA_HOME

  PATH=$PATH:$JAVA_HOME/bin

  export PATH

4-Restart your system

pintu
  • 331
  • 4
  • 7
0

The Eclipse read me document has helped me solve this issue clearly.

If this seems to solve the problem, it is likely that the problem really was related to the use of GCJ as the Java runtime for running Eclipse. The eclipse.ini file located within Eclipse's folder can be altered to automatically pass this argument to Eclipse at startup. An example of its content is presented below:

  -showsplash
  org.eclipse.platform
  -vm
  /opt/jdk-1.8/bin/java
  -vmargs
  -Xms256m
  -Xmx1024m

So I had to put this the line before the -vmargs

Harsha
  • 1,568
  • 2
  • 19
  • 22
  • Erm. My recommendation would be to uninstall GCJ and install OpenJDK instead. GCJ has effectively been "end of life" for many years, and was removed from the GCC source tree in 2016; see https://en.wikipedia.org/wiki/GNU_Compiler_for_Java and https://stackoverflow.com/questions/4035538/is-gnus-java-compiler-gcj-dead – Stephen C May 04 '20 at 07:33
-1

-vm /home/{Users_Directory}/Desktop/jdk-8u251-linux-x64/jdk1.8.0_251/bin