Search code examples
javamavennetbeansmaven-2netbeans-platform

Netbeans Maven project: JAVA_HOME is not defined correctly


I have a NetBeans Platform project build with Maven2. When I try to create a new platform module I get this strange error:

cd ~/src; JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java ~/netbeans-7.3/java/maven/bin/mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes...
Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/lib/jvm/jdk1.7.0/bin/java/bin/java

In ~/.bashrc I have definition of JAVA_HOME:

export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export JDK_HOME="/usr/lib/jvm/jdk1.7.0"

There's no slash at the end, however maven appends /bin/java/bin/java to this path. I can build already existing module with Maven without problems, just when creating a new one it fails. Where does Maven get this JAVA_HOME?

EDIT: maven settings:

$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.7.0_17
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-39-generic" arch: "amd64" Family: "unix"

Solution

  • the problem was with incorrect definition of JAVA_HOME in ~/.bash_profile

    NetBeans integration of maven prefers:

    System.getenv("JAVA_HOME")
    

    before:

    System.getProperty("java.home")