I am on the verge of releasing a project but it seem JAVA_HOME is been inconsistent. Maybe it's been overridden somewhere else? I am using ubuntu 14.04 and I have openjdk-7, java-7-oracle, java-8-oracle. Default java was set using update-java-alternatives
java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
mvn -version gives the following output
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T17:37:52+00:00)
Maven home: /usr/share/maven3
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-39-generic", arch: "amd64", family: "unix"
But when doing mvn release:prepare, below is what I see:
[INFO] Not generating release POMs
[INFO] Executing goals 'clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/lib/jvm/java-8-oracle/bin/java/bin/java
It looks like the java executor is being looked for in the wrong folder : /java/bin/java
. I have tried changing java home to /usr/lib/jvm/java-8-orable/bin
but it broke mvn-version
check.
How to fix this? Thanks for reading
I can't find here to fix that. Has anyone encountered anything similar?
EDIT 1:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<excludes>
<exclude>**/*ITest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<preparationGoals>clean verify</preparationGoals>
<tagBase>https://xxxx/svn/projectname/tags</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I have switched to java-7-oracle and still no chance:
[INFO] Executing goals 'clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/lib/jvm/java-7-oracle/bin/java/bin/java
EDIT 2:
Dear down voters, I am not asking for help about how to set Java Home. It's been set to
/usr/lib/jvm/java-8-oracle
Then to the following when I tried running same thing with java 7
/usr/lib/jvm/java-7-oracle
This is set in /etc/profile.d/jdk.sh by webup8 script
export J2SDKDIR=/usr/lib/jvm/java-7-oracle
export J2REDIR=/usr/lib/jvm/java-7-oracle/jre
export PATH=$PATH:/usr/lib/jvm/java-7-oracle/bin:/usr/lib/jvm/java-7-oracle/db/bin:/usr/lib/jvm/java-7-oracle/jre/bin
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
export DERBY_HOME=/usr/lib/jvm/java-7-oracle/db
EDIT 3
I have switched to openjdk 7 , edited the jdk.sh to reflect this export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
and the error went. I run to other famous issues (permission issues to tags folder. weird) . So it's not related to the maven itself I guess. But this is weird that it works fine for openjdk ...
JAVA_HOME must point to jre, not jdk. Then set :
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
Creating a file .mavenrc
on my home folder and adding the code below solved the problem for me. (Ubuntu 14.10, Maven 3.2.1)
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
Another workaround:
export JAVACMD=$JAVA_HOME/bin/java
setting /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45 did not work for me
I spend quite some time to tackle similar error. It looks like package manager might create mess in Java installations. Path to Java is sometimes hardcoded in bash files. I found one in /etc/profile.d/jdk.sh
. It just overrides your settings. Another fix/workaround for that is to update symlink, in my case it was /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45
. Try to look for java/bin
text in all bash files.
in super user privilege on your terminal open
vi etc/environment
on opened file add JAVA_HOME path
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/"
Hope you set the JAVA_HOME check if your JAVA_HOME is set using command
echo $JAVA_HOME
I used OpenJDK as default java , updated JAVA_HOME in /etc/environment and all the issues went. Thanks for all your effort helping me through this
I had the same problem. My workaround was:
cd /usr/lib/jvm/java-8-oracle/jre/bin
sudo ln -s /usr/lib/jvm/java-8-oracle/bin/java java
来源:https://stackoverflow.com/questions/26776303/having-java-home-inconsistency-issue-with-maven