4

For various reasons, I must stick with older versions of Java (6) and Maven (2.2). So with that I mind, I installed Maven 2.2.1 while my system uses the 64-bit JDK 6.

I tried to verify that it is correctly installed by running mvn --version and what I received in response was:

ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Windows:\Program Files\Java\jdk1.6.0_37"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation

I am suspecting that Maven expects the 32-bit version of Java and that it cannot deal with 64-bit Java. Is this true?

If indeed this is the case, setting the %JAVA_HOME% environment variable to point the 32-bit version (already installed) is not what I would like to do because it will then fail other tools installed on my PC that count on it pointing to the 64-bit version.

Is there a way around this?

UPDATE: Problem solved by inserting into maven.bat the following line (just before === START VALIDATION ===):

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_37

This way, this %JAVA_HOME% environment change is localized to Maven and is not visible outside.

If there is a better solution, I would be happy to know about it.

Withheld
  • 4,603
  • 10
  • 45
  • 76
  • Where is the relationship to Maven 2.2.1 and the Java version ? You should use Maven 3.0.X instead of Maven 2.2.1 ... – khmarbaise Nov 30 '12 at 14:30
  • @khmarbaise I am using the [xmlbeans-maven-plugin](http://stackoverflow.com/a/13707097/1864054) which only supports Maven 2, not 3. So unfortunately I can't use Maven 3. – Withheld Dec 04 '12 at 17:01
  • Where is that written? I don't see a hint on the mojo codehaus pages that this plugin works only in Maven 2...? – khmarbaise Dec 04 '12 at 17:10
  • 1
    @khmarbaise http://mojo.codehaus.org/xmlbeans-maven-plugin/index.html – Withheld Dec 04 '12 at 19:35
  • 1
    The point is that Maven 3 is a drop-in replacement for Maven 2. So usually there are no problems with Maven plugins. This was mentioned there, cause to make clear it can't be used with Maven 1. – khmarbaise Dec 05 '12 at 08:33
  • @khmarbaise OK, that's good to know that at some point I will be able to upgrade to Maven 3 without losing the `xmlbeans-maven-plugin`. I am working within a team that dictates that we should still stay with Maven 2, so the constraint is still there, but as seen in my answer below, I solved my problem: Maven really needs a valid `%JAVA_HOME%`. :-) – Withheld Dec 05 '12 at 13:34

1 Answers1

3

The source of the problem was in front of my eyes all that time but I didn't see it:

The %JAVA_HOME% env var was set to %SystemRoot%\Program Files (x86)\Java\jdk1.6.0_37 instead of %SystemDrive%\Program Files (x86)\Java\jdk1.6.0_37.

Once fixed, no modification of maven.bat is required.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Withheld
  • 4,603
  • 10
  • 45
  • 76