我即将发布项目,但似乎JAVA_HOME不一致。也许它在其他地方被覆盖了?我正在使用ubuntu 14.04,我有openjdk-7,java-7-oracle,java-8-oracle。默认Java是使用update-java-alternatives设置的

Java版本

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提供以下输出
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"

但是当执行mvn release:prepare时,下面是我看到的内容:
[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

似乎在错误的文件夹/java/bin/java中寻找了Java执行程序。我尝试将java home更改为/usr/lib/jvm/java-8-orable/bin,但它破坏了mvn-version检查。

如何解决这个问题?谢谢阅读

我在这里找不到解决该问题的方法。有没有人遇到过类似的事情?

编辑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>

我已经切换到java-7-oracle,仍然没有机会:
[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

编辑2:

亲爱的选民,我不是在寻求有关如何设置Java Home的帮助。它被设置为
/usr/lib/jvm/java-8-oracle

然后,当我尝试使用Java 7运行相同内容时,显示以下内容
/usr/lib/jvm/java-7-oracle

这是通过webup8脚本在/etc/profile.d/jdk.sh中设置的
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

编辑3

我已切换到openjdk 7,编辑了jdk.sh以反射(reflect)此export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64,并且错误消失了。我遇到了其他著名的问题(标签文件夹的权限问题。很奇怪)。因此,我猜它与Maven本身无关。但这很奇怪,对于openjdk来说效果很好...

最佳答案

JAVA_HOME必须指向jre,而不是jdk。然后设置:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre

09-11 18:55
查看更多