After I run maven install I get this message from eclipse:
Reason:
Unable to locate the JavacCompilerin: C:\Program Files(x86)\Java\jre6\..\lib\tools.jar Pleaseensure you are using JDK 1.4or above andnot a JRE (the com.sun.tools.javac.Mainclassis required).In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.
I'm certain that this is the tricky part
Please ensure you are using JDK 1.4 or above and not a JRE
When I run configuration its set to JRE6, how do I change it to JDK 1.6 which I have already installed
Maybe I forgot to say I use eclipse maven plugin .. how can I change from JRE to JDK in eclipse ?
回答1:
You could try updating the JDK Eclipse is using, as follows:
Add and set the JRE in Window->Preferences...->Java->Installed JREs:
JRE type:Standard VM JRE Name: jdk1.6.0_18 JRE home directory: C:\Program Files(x86)\Java\jdk1.6.0_18
If this is not the case, it's possible that the brackets and spaces in the JAVA_HOME path are causing issues. Try copying your JDK to a different location and updating your JAVA_HOME.
回答2:
eclipse.ini needs the vm argument to point to your jdk location.
Edit the eclipse.ini file to point to your jdk home, something as follows -
-vm C:\Program Files\Java\jdk1.6.0_06
This ensures that Eclipse would be running off the JDK and not any default JRE on your machine.
回答3:
You try:
Go to Preferences/Java/Installed JREs and add one for the location "C:\Program Files\Java\jdk1.6.0_27\jre or something like that.
Remove the one for C:\Program Files\Java\jre6
As you can see, the path C:\Program Files\Java\jre6\..\lib\tools.jar only makes sense if the first part (til the /..) is replaced by C:\Program Files\Java\jdk1.6.0_27\jre.
回答4:
Setting Fork to true resolved the issue for me.
true1.61.6
Thank you very much, Sam Yang..you made my day
回答5:
I had EXACT the same problem! Been searching and searching for days because all the babble about "put the -vm c:\program files\java\jdkxxxxx\bin" in the ini ar as argument for a shortcurt did NOT AT ALL heklp! (Do I sound frustrated? Believe me, that's an understatement! I am simply furious because I lost a week trying to make Maven reliable!)
I had very unpredictable behavior. Sometimes it compiled, sometimes not. If I did a maven clean, it could not find the compiler and failed. If I then changed something in the build path, it suddenly worked again!!
Until I went to window -> preferences -> java -> installed JRE's. I added a new JRE using the location of the JDK and then removed the JRE. Suddenly maven ran stable!
Maybe this is worth putting in letters with font-size 30 or so in the apache manual? With all due respect, this is simply outrageous for the java community! I can't imagine how many days were lost by all these people, trying to work out their problems of this kind! I cannot possibly imagine this is released as a final version. I personally would not even dare to release such a thing under the name BETA software...
Kind regards either way.... After a week of tampering I can finally start developing. I hope my boss won't find out about this. It took me lots of effort to convince him NOT to go to .NET and I already feel sorry about it.
回答6:
I got the same problem using Run as -> Maven install in Eclipse. JAVA_HOME and eclipse.ini were OK and pointing to my latest JDK. But m2clipse used JRE. Using mvn install outside of Eclipse worked fine! In my case I solved the problem as follows: 1. Navigate in Eclipse: Window -> Preferences -> Java -> Installed JREs 2. There were two inactive entries for a JRE and JDK. The active one was the latest installed JDK. Delete all entries but the one maven should use.
I think maven doesn't take into acount which one is active...
回答7:
I have just install maven 3.0.4, set M2_HOME, M2 and JAVA_HOME accordingly. I then ran the following commands:
mvn archetype:generate....
mvn compile
I got failed message such as: maven unable to locate javac compiler.
On my computer, I have default jre install at c:\program files\java\jre.1.6. And I have the other c:\java\jdk1.6 and JAVA_HOME set to this c:\java\jdk1.6.
I don't see anything wrong with my setting. After searching, I decided to look into mvn.bat, I echoed %JAVA_HOME% every step and it displays correctly as C:\java\jdk1.6 but when I run the command : mvn --version, it displays Java home: c:\program files\java\jre1.1.6.
Finally, I found out that I just need to set -Djava.home=c:\java\jdk1.6 as in the command below, and working fine now:
Note: This is for mvn on command line and not with Eclipse.
回答8:
It sounds like Maven is using the JRE, not the JDK. Perhaps you installed Maven before installing the JDK?
Check the settings files. There are 3 in total, system, user, and project. Its most likely in the installation config ($M2_HOME/conf/settings.xml) or, possibly, the per-user config (${user.dir}/.m2/settings.xml).
I solved the issue by changing location of Installed JRE to the directory present in JDK itself. Setting proper value of JAVA_HOME environment variable did not solve the issue.
In my case, there are two directories
C:\Program Files\Java\jdk1.7.0_03 --> For JDK
C:\Program Files\Java\jre7 --> For JRE
Initially I set C:\Program Files\Java\jre7 as Installed JRE in Eclipse and I was getting the same error in case of Maven(Ant was working fine).
By changing the installed JRE to C:\Program Files\Java\jdk1.7.0_03\jre7 as Installed JRE in Eclipse the issue is solved.
回答11:
Eclipse setup only
Do the following steps:
Right Click on Eclipse project Properties
Java Build Path -> Libraries
Select JRE System Library -> Click Edit button
Click "Installed JREs..." button
Edit JRE as: Set JRE Home = JAVA_HOME or JAVA_HOME\jre
ScreentShot:
Many Thanks,
Partha
回答12:
Right click on Project -> Properties -> Java Build Path. Select the JRE System Path -> Edit. Select the Workspace Default JRE, and point it to JDK > 1.4
回答13:
Window -> Preferences -> Java -> installed JREs -> Execution Enviroments -> click the checkbox on the right side
回答14:
The solution is simple, some times the eclipse windows -> preference -> java -> Installed JREs pointing to C:\Program files\Java\jre, when i changed it to C:\Program files\Java\JDK 6.0\jre it is working 100%.
回答15:
As mentioned by several others, the Eclipse Window->Preferences...->Java->Installed JREs should point to the JDK you installed, not to the JRE. Only then it can find the ../lib folder mentioned in the error message.
Even with this, the problem may recur. My way out in Eclipse (Juno) is to do a Maven -> Update project... after which the problem disappears.
I suspect the reason is that some of the Eclipse generated files (.classpath, .project, .preferences) are in subversion for the project in which I'm having these problems. Thus, an svn update introduces the problem, and an configuration update from maven in Eclipse resolves it again.
Real solution: omit Eclipse generated .files from version control, and let the maven eclipse plugin handle project configuration. (additional pointers/suggestions welcome).
回答16:
Don't forget that if you are running your project from a particular Eclipse configuration, you should change the Java Runtime within 'Run Configurations' --> 'Your maven configuration' --> 'JRE tab'after you add the right JDK to your Eclipse preferences.
回答17:
In my case, in eclipse Run-> Debug Configurations In the jre tab selected the jdk instead of the jre solved the problem.
回答18:
Go to the Eclipse Window->Preferences...->Java->Installed JREs should point to the JDK you installed, not to the JRE.
回答19:
I would guess that the location of the compiler is defined in a pom for the compiler plugin to be in the jre location displayed, instead of the jdk location you have JAVA_HOME pointing to.
回答20:
If you set the JAVA_HOME, and the problem persists try the following. (i had the same problem, on a fresh installed pc.)
Assuming you are using Eclipse.
Open Window - preferences - java - installed jre's remove all you have there, add the desired you want to use (JDK, no JRE!)
In the same window open maven - installations, add the mave installation you downloaded and extracted somewhere. (DO NOT USE the embedded maven installation, it has some known bugs)
Thats all. your project will not suffer from sutch problems. Hope helps.
回答21:
You can also make sure that Eclipse has all of the updated changes. To do this, right-click your project and then press the "Refresh" menu item.
回答22:
You need to indicate JAVA_HOME in mvn.ini (it's in the maven folder /bin), and your problem will disappear.
回答23:
Many other answers tell you to point your Eclipse to a JDK instead of a JRE.
Here is another answer with more specific/clear [than I have seen in any answer here] step-by-steps on how to do that:How do you install JDK?
That is what for solved me for this same problem.
回答24:
I had the same Error, because of JUNIT version, I had 3 3.8.1 and I have changed to 4.8.1.
so the solution is
you have to go to POM, and make sure that you dependency looks like this
junitjunit4.8.1test
回答25:
I changed the configuration of maven-compiler-plugin to add executable and fork with value true.