m2eclipse is unable to locate C:\Program Files\Java\jre6\..\lib\tools.jar

11,897

Solution 1

I figured out a workaround that seems to work. It's not really that what I hoped to be a solution but at least I can use maven now.

I created a new folder on the same level in the file system as the jdk and the jre folders are. I called it lib and copied the tools.jar file form the jdk into it.

Additionally I switched from the "normal" eclipse for java SE to the eclipse for Java EE (I'm using EJBs). The version of eclipse is the one we got from university so i don't know if a plugin is installed which I missed to install on my (java SE) eclipse.

Now It seems to work but if anybody has a solution that might solve that problem in a more elegant way please let me know.

Solution 2

  1. Go to Windows --> Installed JREs
  2. select the installed JRE and click edit
  3. change the JRE home directory to PATH_TO_YOURJDK\jre (previously it would be PATH_TO_YOUJRE)
  4. this works for me

Solution 3

See this answer. It suggests that you need to set your PATH to point to the Java bin directory. In my own case this is set:

D:\workspace>echo %PATH%
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem; ...
C:\Program Files\Java\jdk1.7.0_02\bin; ...

Solution 4

EDIT: You mentioned you have the JRE in your JDK referenced in your build path. Well did you notice that tools.jar is NOT in this JRE folder either? tools.jar is contained in the /lib folder only. Not the JRE inside the JDK.

This kept popping up for me in my project as well. For whatever reason, Eclipse keeps telling me it's unable to locate tools.jar. I have fixed it a few time for this project and tonight it came back. Below is how I ended up fixing it once and for all.

The reason is that you have JRE6 in your included libraries in your Java Build Path. However tools.jar is not included in any JRE, you need to import tools.jar from your JDK.

By simply going to Properties for -> Java Build path -> Libraries (Tab) -> Add External JARs.. and choosing your JDKs tools.jar file in the /lib folder, it fixes the problem. See the image below.

enter image description here

Solution 5

I notice this is already an old question, but there is a better solution for this. First of all, Eclipse ask "Installed JREs", but actually you should provide the JDK here. Like Styler kind of mentioned, but instead of importing the tools.jar separatedly just define the JDK in "Installed JREs". Then it will find everything there is needed from "basic java" without extra imports to build path (also you should not move anything to or from the JDK folder, this can break the portability of the software). Also notice that when selecting "project" > "Java Compiler" there is an option: "Enable project specific settings". If you have this option selected, it may have a different "JRE" specified to be used than what you have in "Window" > "Preferences" > "Java" > "Installed JREs" selected as default.

Share:
11,897
mvieghofer
Author by

mvieghofer

Web Developer #SOreadytohelp

Updated on June 04, 2022

Comments

  • mvieghofer
    mvieghofer about 2 years

    I have a problem, concerning the jdk/jre usage of my eclipse. I know that this question was asked and answered a lot of times here and I researched what could be wrong for quite a while. I actually didn't find anything so I'm going to ask you again. Maybe I'm missing something (if yes, I hope it's not to embarrasing :)

    My problem is, that when I'm running mvn clean install I get an error which says that the m2eclipse plugin is "Unable to locate the Javac Compiler in: C:\Program Files\Java\jre6..\lib\tools.jar".

    First thing I checked was if the right JRE was configured in eclipse. So I switched into Window > Preferences > Java > Installed JREs and checked if the selected jre is the jre inside my jdk folder. This was the case.

    I checked the eclipse.ini and added a -vw flag to it. It now looks like:

    -startup
    plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
    -product
    org.eclipse.epp.package.java.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -showsplash
     org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    --launcher.defaultAction
    openFile
    -vm
    "%JAVA_HOME%\bin\javaw.exe"
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx384m
    

    The %JAVA_HOME% is resolved to C:\Program Files\Java\jdk1.6.0_24. Since it contains a space I surrounded the vw path with quotes. To check if the path is really correct I tried

    C:\Windows\System32>echo %JAVA_HOME%
    C:\Program Files\Java\jdk1.6.0_24
    

    which tells me that it is correct. I also tried to pass the -vw option when eclipse is started. So the command to start eclipse was then

    D:\Programs\eclipse\eclipse.exe -vm "%JAVA_HOME%\bin\javaw.exe"
    

    I also tested if there is a difference when I use the %JAVA_HOME% notation or if I writed the full path (it makes no difference).

    The configuration of eclipse, which I get when I go to Help > About Eclipse > Installation Details > Configuration, looks like that:

    __wbp.gwt.useWebKit=true
    awt.toolkit=sun.awt.windows.WToolkit
    veclipse.application=org.eclipse.ui.ide.workbench
    eclipse.buildId=M20120208-0800
    eclipse.commands=-os
    win32
    -ws
    win32
    -arch
    x86_64
    -showsplash
    -launcher
    D:\Programs\eclipse\eclipse.exe
    -name
    Eclipse
    --launcher.library
    D:\Programs\eclipse\\plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110    502\eclipse_1406.dll
    -startup
    D:\Programs\eclipse\\plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
    --launcher.overrideVmargs
    -exitdata
    3e30_64
    -product
    org.eclipse.epp.package.java.product
    -vm
    C:\Program Files\Java\jdk1.6.0_24\bin\javaw.exe
    eclipse.home.location=file:/D:/Programs/eclipse/
    eclipse.launcher=D:\Programs\eclipse\eclipse.exe
    eclipse.launcher.name=Eclipse
    [email protected]/../p2/
    eclipse.p2.profile=epp.package.java
    eclipse.product=org.eclipse.epp.package.java.product
    eclipse.startTime=1335643108722
    eclipse.vm=C:\Program Files\Java\jdk1.6.0_24\bin\javaw.exe
    eclipse.vmargs=-Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx384m
    -XX:MaxPermSize=256m
    [...]
    

    I also tried to use the javaw.exe that is located in %JAVA_HOME%\jre\bin\ which also doesn't change anything.

    One thing that is a little bit strange is, that if I delete the reference to the jre, the one that is not included in jdk, in Window > Preferences > Java > Installed JREs I get an error which says "The specified JRE installation does not exist".

    Does anyone have an idea what I'm doing wrong? I think I tried anything to make it work and according to the other articles I found I'm doing it right.

    Btw: I did some Maven "Update Project Dependencies" and "Update Dependencies" which work, so I did not get any error there. The only thing, I did not do is to restart my computer...

  • mvieghofer
    mvieghofer about 12 years
    I had the jdk on my path, so that was not the problem.
  • Ville Myrskyneva
    Ville Myrskyneva about 10 years
    I happened to notice that m.ali.khan.5049 had earlier provided basically the same information. I just happened to miss that by the time of writing. But I hope that the extra information provided may benefit someone.