我正在尝试使用JDK 7编译Storm Starter

$ 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


根据this线程,我使用了错误的Java版本,应该使用Java7。但是我的Java版本是7。编译时。如何使该项目编译?

最佳答案

您需要确保$JAVA_HOME/bin(或至少1.7 java可执行文件)首先出现在您的PATH中,因为这是插件使用的。

通过将JAVA_HOME指向JDK 1.7,我可以通过在java中首先将路径设置为PATH(JDK 1.6目录)来复制此问题。 clojure-maven-plugin代码尝试确定此路径,并退回到在当前环境/ java中仅使用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";
  }

10-04 21:00