1

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?

Community
  • 1
  • 1
Jamie
  • 2,181
  • 1
  • 21
  • 35

1 Answers1

2

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";
  }
Will Hogan
  • 909
  • 4
  • 9
  • Yea, this is off of a fresh git clone. I think I built `closure-maven-plugin` with a different version of Java, and possibly that's cached somewhere. Here's a link to the error output of `mvn install -DskipTests`: http://pastebin.com/MmhZVe4w – Jamie Oct 18 '15 at 00:04
  • Looks like the `clojure-maven-plugin` juse uses whatever is in your current environment, both for Clojure versions and JDK. Something in the toolchain is just falling back to the "`java`" command in the `PATH` rather than going to `JAVA_HOME/bin`. Seems that's the fallback at line 247 here - https://github.com/talios/clojure-maven-plugin/blob/clojure-maven-plugin-1.7.1/src/main/java/com/theoryinpractise/clojure/AbstractClojureCompilerMojo.java – Will Hogan Oct 18 '15 at 00:13
  • Okay, I ran `sudo update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 0`, followed by `sudo update-alternatives java`. I'll update after installation is done, but right now `mvn install` seems to be running fine :) – Jamie Oct 18 '15 at 00:27
  • Yep, that did it! So my problem was that the java on my PATH didn't match the java in $JAVA_HOME. If you edit your answer I'll accept it. – Jamie Oct 18 '15 at 00:40