Having JAVA_HOME inconsistency issue with maven
Asked Answered
B

7

10

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

Businesswoman answered 6/11, 2014 at 9:52 Comment(9)
Do you have full JDK installed or only JRE? Does it work with java-7? What compiler options are in your pom?Michaelamichaele
yes full jdk was installed. doesn't work with java 7 either. I have edited the post.thanksBusinesswoman
possible duplicate of How to set Oracle's Java as the default Java in Ubuntu?Beltz
Vote down huh!? How did you arrive at the conclusion my java home is not set to what your post is referring to? I am not asking for help as to how to set java home, come on... If you care to read you will at least understand that this is all about how Java Home is being read by maven.like seriously..... why do you downvote me over something you don't even understand?Businesswoman
Please post the full mvn -X log.Marchant
@Beltz Clearly not a duplicate.Marchant
Release plugin does complex job including source operations. But what if you run "clean verify" or just "clean"?Michaelamichaele
clean verify, release:clean, install, clean install, release:rollback are all fine.Businesswoman
changed to openjdk without any tweaking and it built and released fine. What a shocker.Businesswoman
B
0

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

Businesswoman answered 22/4, 2015 at 14:6 Comment(0)
S
10

JAVA_HOME must point to jre, not jdk. Then set :

export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
Semiconscious answered 12/11, 2014 at 8:7 Comment(1)
Hello This was actually the case, before I moved to oracle-java 7Businesswoman
B
6

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
Braddy answered 24/3, 2015 at 18:32 Comment(0)
K
2

Another workaround:

export JAVACMD=$JAVA_HOME/bin/java

setting /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45 did not work for me

Kaela answered 28/12, 2014 at 9:53 Comment(0)
L
1

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.

Ladonnalady answered 12/11, 2014 at 8:19 Comment(0)
O
1

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
Oligosaccharide answered 24/3, 2015 at 19:31 Comment(0)
B
0

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

Businesswoman answered 22/4, 2015 at 14:6 Comment(0)
S
0

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
Sasha answered 6/8, 2018 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.