views:

2036

answers:

7

Hi all,

I have my JAVA_HOME set to

C:\Program Files (x86)\Java\jdk1.6.0_18

After I run maven install I get this message from eclipse:

Reason:

Unable to locate the Javac Compiler in:
  C:\Program Files (x86)\Java\jre6\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is 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

EDIT

I even tried to modify the plugin :

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <executable>C:\Program Files (x86)\Java\jdk1.6.0_18\bin</executable>
                </configuration>
            </plugin>

Still I get the same error

Maybe I forgot to say I use eclipse maven plugin .. how can I change from JRE to JDK in eclipse ?

A: 

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.

Robin
@Robin Where exactly should I look for that ? the pom looks fine to me `<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target>`
Gandalf StormCrow
If there is not an <executable> defined, then this is not what is causing your problem, unless the pom you are looking at inherits from a parent pom which has it defined.
Robin
@Robin I defined the executable already I edited my question
Gandalf StormCrow
When defining the executable, you also have to set <fork> to true.
Robin
+6  A: 

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.

lrussell
It is indeed the first part of your question, JAVA_HOME thing is ok
Gandalf StormCrow
+1  A: 

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

Devon_C_Miller
A: 

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

Markus
A: 

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

Lorenzo
@Lorenzo bottom line, use it from console not from eclipse you won't have this kind of issues, that is what I've realized after few months of using it, now pretty comfortable with maven
Gandalf StormCrow
A: 

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

asHIS