1

I downloaded a Github project my team will be doing development work for (it's private, so sharing it wouldn't help). It includes a pom.xml file with the following dependency:

 <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.3.2</version>
         <configuration>
              <source>1.7</source>
              <target>1.7</target>
             <showDeprecation>true</showDeprecation>
            <showWarnings>true</showWarnings>
         </configuration>
 </plugin>

This project depends on having Java 7. Researching this issue in other people's cases- it looks like their versions are inconsistent between java and mvn, and the JAVA_HOME environmental variable, so let me show you some Terminal output:

Last login: Thu Jun  5 13:05:34 on console
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home
$ mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00)
Maven home: /usr/local/apache-maven-3.2.1
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
$ javac -version
javac 1.7.0_60

It looks like Java 7 is successfully installed on my Mac, the environmental variable for JAVA_HOME is correctly set, and maven claims to have the Java version I need.

Within top level directory of that project I cloned from Github, which I will just call "githubproject", I run:

sudo mvn clean install

It runs, with good output for a while... until this:

[INFO] Compiling 239 source files to /usr/local/gardens/githubproject/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options

[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.793 s
[INFO] Finished at: 2014-06-05T13:08:38-05:00
[INFO] Final Memory: 26M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project hgtvgardens: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.7
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[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

So here is an interesting thing is that if I go into that pom.xml file- I can change the dependency from 1.7 to 1.6, and the mvn clean install command runs just fine- build success... However, the project has all sorts of Java errors where Java 7 was required to compile certain parts (though other parts of the project still work).

My best guess is that it's an environmental issue- but why is there an issue, and where could it be?

In researching, other people have solved their problem by copying tools.jar into /Library/Java/Extensions/ ... which I did- but to no result.

Why doesn't installing Java for Mac take care of these issues, since I haven't done much to customize Java settings outside of setting JAVA_HOME in ~/.bash_profile

Is there a system link I need to change?

Link Update

One of my team members ran

sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

and it fixed his build error- but he is getting the same issues where it looks like the project was compiled wrong.

Other team members have no issues at all- same OS, hardware, Github project, and software... something is different- and I'm not sure what...

Mavan Compiler Plugin Update

Someone suggested using a more updated maven compiler.

Downloaded maven-compiler-plugin-3.1.jar from http://search.maven.org/#artifactdetails|org.apache.maven.plugins|maven-compiler-plugin|3.1|maven-plugin and copied it into my apache-maven/lib directory (this is a complete guess). Then I updated the pom.xml to use 3.1 instead of 2.3.2

The result:

[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 
(default-compile) on project githubproject: Execution default-compile of goal 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile failed: 
A required class was missing while executing 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile: 
org/codehaus/plexus/compiler/util/scan/mapping/SuffixMapping

I might have done this wrong.

(My) Answer

I figured it out- the permissions weren't allowing access to the files in that githubproject. I just had to change permissions to those files and it successfully built. (Putting the compiler plugin under my mavin lib directory broke maven for a while, but I finally got rid of that ill-placed jar). Thanks to everyone who gave this attention- the error was a red herring.

  • Use a more up-to-date version of the [maven-compiler-plugin (3.1)](http://search.maven.org/#artifactdetails%7Corg.apache.maven.plugins%7Cmaven-compiler-plugin%7C3.1%7Cmaven-plugin). (BTW: Why are you calling mvn via sudo?). – khmarbaise Jun 05 '14 at 17:36
  • theres also this possibility http://stackoverflow.com/questions/14043042/compiling-java-7-code-via-maven try the awnsers on that question and see if that helps. (PS: are you guys sharing a maven installation?!) – ug_ Jun 05 '14 at 17:39
  • @khmarbaise I am on a work computer with occasionally odd permission issues- just need to go around and clean-up, but I doubt running it via sudo is the issue. Will look at using an updated maven compiler. Where should I put that plugin.jar? – bfosterscripps Jun 05 '14 at 17:40
  • @ug_ I read that and checked it- looks like it should come out with the proper JAVA_HOME, especially since I'm defining it. The script would output something if it hit any of that logic too... so it doesn't seem to be that the mvn script is overriding with the wrong Java We all installed maven separately- but all installed the same version (so, yes- we are all using the same maven install, but not necessarily the numerically same file... so it would be an edge case that we have different mvn installs). – bfosterscripps Jun 05 '14 at 17:42
  • tried the 3.1 compiler plugin (updated pom.xml to say 3.1 instead of 2.3.2), will update main description with output... – bfosterscripps Jun 05 '14 at 18:02
  • @bfosterscripps I would try (in order of easiest to most time consumping): 1) call `javac -version` just to be sure about the version. 2) call `which javac` in bash to see possible locations of other java compiler installations 3) Run maven in full debug mode to see more detail `mvn clean install -X` and dredge through the output to find where the issue lies. – ug_ Jun 05 '14 at 18:02
  • @ug_ I have done all of these things already- I didn't include the results of which javac - which is merely /usr/bin/javac- (though I did include javac -version in my original description). The -X flag doesn't give us much more info other than it has to do with some Java class named Mojo...which we can tell without the flag. – bfosterscripps Jun 05 '14 at 18:10

1 Answers1

0

I have fully replaced my Mac OS Java with 1.7 downloaded directly from Sun a while ago. It did require a bit of tinkering with the links to the CurrentJDK, but here is the result. Hopefully this will help as it looks like your Java installation is somehow broken:

Which OS:

System Version: OS X 10.9.3 (13D65)
Kernel Version: Darwin 13.2.0

Which java do I have and where it is:

schroedinger:backend olegs$ javac -version
javac 1.7.0_40

schroedinger:backend olegs$ which javac
/usr/bin/javac

So where is it actually installed and how:

schroedinger:Versions olegs$ ls -la /usr/bin/javac
lrwxr-xr-x  1 root  wheel  75 31 Okt  2013 /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac

schroedinger:Versions olegs$ pwd
/System/Library/Frameworks/JavaVM.framework/Versions

Which JVM is actually there under Current. Pay attention there is CurrentJDK (pointing to 1.6 in a different location) and Current (pointing to 1.7). The actual 1.7 JDK is installed here in the directory 1.7:

schroedinger:Versions olegs$ ls -la
total 64
drwxr-xr-x  11 root  wheel  374 31 Okt  2013 .
drwxr-xr-x  12 root  wheel  408 21 Apr 19:42 ..
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.4 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.4.2 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.5 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.5.0 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.6 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.6.0 -> CurrentJDK
drwxr-xr-x   8 root  wheel  272 31 Okt  2013 1.7
lrwxr-xr-x   1 root  wheel    1 31 Okt  2013 Current -> 1.7
lrwxr-xr-x   1 root  wheel   59 31 Okt  2013 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

What does my pom say:

schroedinger:backend olegs$ grep jdk.version pom.xml 
    <jdk.version>1.7</jdk.version>

...    
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>

Do I need JAVA_HOME? No:

schroedinger:backend olegs$ echo $JAVA_HOME

What is my maven? It is installed with homebrew:

schroedinger:backend olegs$ which mvn
/usr/local/bin/mvn

schroedinger:backend olegs$ ls -la /usr/local/bin/mvn
lrwxr-xr-x  1 dev  staff  29 31 Okt  2013 /usr/local/bin/mvn -> ../Cellar/maven/3.0.5/bin/mvn

Does it compile?

schroedinger:backend olegs$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.407s
[INFO] Finished at: Thu Jun 05 20:35:48 CEST 2014
Oleg Sklyar
  • 9,834
  • 6
  • 39
  • 62