简体   繁体   中英

Why doesn't closure-maven-plugin pick up the correct Java version?

I'm trying to compile Storm Starter with JDK 7.

$ echo $JAVA_HOME                                                                                                 [master] 
/opt/jdk1.7.0_80

$ mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /opt/jdk1.7.0_80/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-65-generic", arch: "amd64", family: "unix"

$ mvn clean install -DskipTests=true
                ...
[INFO] --- clojure-maven-plugin:1.7.1:compile (compile-clojure) @ storm-core ---
Compiling backtype.storm.LocalDRPC to /home/incubator-storm/storm-core/target/classes

Exception in thread "main" java.lang.UnsupportedClassVersionError: backtype/storm/ILocalDRPC : Unsupported major.minor version 51.0, compiling:(backtype/storm/LocalDRPC.clj:17:1)
Caused by: java.lang.UnsupportedClassVersionError: backtype/storm/ILocalDRPC : Unsupported major.minor version 51.0

According to this thread, I'm using the wrong version of Java, and I should be using Java 7. But my Java version is 7. So my hunch is that closure-maven-plugin is not picking up the correct Java version when compiling. How can get this project to compile?

You need to ensure that $JAVA_HOME/bin (or at least the 1.7 java executable) are first in your PATH as this it's what's used by the plugin.

With JAVA_HOME pointing to JDK 1.7, I was able to duplicate this issue by setting the path to java (JDK 1.6 directory) first in my PATH . The clojure-maven-plugin code tries to determine this path and falls back to using just java in the current environment/ PATH :

 private String getJavaExecutable() throws MojoExecutionException {

    Toolchain tc = toolchainManager.getToolchainFromBuildContext("jdk", //NOI18N
                                                                 session);
    if (tc != null) {
      getLog().info("Toolchain in clojure-maven-plugin: " + tc);
      String foundExecutable = tc.findTool("java");
      if (foundExecutable != null) {
        return foundExecutable;
      } else {
        throw new MojoExecutionException("Unable to find 'java' executable for toolchain: " + tc);
      }
    }

    return "java";
  }

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