简体   繁体   中英

Maven 3.2.1 on Mac OSX 10.9.2 is incorrectly using JRE 7 and not JDK 7

I have tried following the instructions at After Installing Java JDK 7 For Mac OS X - mvn -version still shows java version 1.6.0_31 but they do not fix my issue. :-(

When I run:

mvn clean install

I get the following issue:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JBehave JUnit Runner 1.2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jbehave-junit-runner ---
[INFO] Deleting /Users/skurlow/IdeaProjects/mygithubforks/jbehave-junit-runner/target
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ jbehave-junit-runner ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jbehave-junit-runner ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/skurlow/IdeaProjects/mygithubforks/jbehave-junit-runner/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jbehave-junit-runner ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /Users/skurlow/IdeaProjects/mygithubforks/jbehave-junit-runner/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.164 s
[INFO] Finished at: 2014-04-18T07:25:53+10:00
[INFO] Final Memory: 11M/126M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jbehave-junit-runner: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I have Oracle's JDK7 installed:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home

I added to my pom.xml because maven was some how deciding to use source and target of 1.5 rather than 1.7:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

When I run:

mvn clean install -X

I see it is telling me that JRE is being used and not the JDK. But I cannot for the life of me change maven to use JDK instead of JRE. :-(

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T04:37:52+10:00)
Maven home: /Users/skurlow/tools/apache-maven-3.2.1
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"
[INFO] Error stacktraces are turned on.

The output of running:

mvn --version

is:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T04:37:52+10:00)
Maven home: /Users/skurlow/tools/apache-maven-3.2.1
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

The output of running:

javac -version

is:

javac 1.7.0_55

I have had the same error in the windows environment. The solution was to set the JAVA_HOME environment variable to the JDK path and not JRE path. This was:

JAVA_HOME = C:\\Program Files\\Java\\jdk1.7.0_55

PATH = %JAVA_HOME%\\bin

Ensure that you follow maven install instructions for OSX. for you this might be:

Make sure that JAVA_HOME is set to the location of your JDK, eg export JAVA_HOME=/usr/java/jdk1.7.0_51 and that $JAVA_HOME/bin is in your PATH environment variable.

The fix was to delete tools.jar from my home directory in ~/Library/Java/Extensions

For an unknown reason I had a JDK5 version of it lying around in there.

You can also check and remove it if you have it in the root folder in /Library/Java/Extensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM