2

I'm upgrading a maven project to compile with Java 8 from Java 7.

The installed java versions on my machine are

pauloconnell@pauloconnell-HP-ZBook-15:~/$ update-java-alternatives -l
java-7-oracle 1076 /usr/lib/jvm/java-7-oracle
java-8-oracle 1077 /usr/lib/jvm/java-8-oracle

And my JAVA_HOME is set

pauloconnell@pauloconnell-HP-ZBook-15:~/$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

Any these are the details in my .bashrc file

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export MAVEN_HOME=/usr/share/maven/bin
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin

When i run 'mvn compile' on a module with this plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <configuration>
        <factory>com.infonova.om.il.apt.Factory</factory>
        <showWarnings>true</showWarnings>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I get

[ERROR] Failed to execute goal org.codehaus.mojo:apt-maven-plugin:1.0-alpha-5:process (default) on project om-interface-eircom: Unable to locate the apt compiler in:
[ERROR] /usr/lib/jvm/java-8-oracle/jre/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.5 or above and
[ERROR] not a JRE (the com.sun.tools.apt.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.

I found these existing issues

http://stackoverflow.com/questions/8375423/missing-artifact-com-suntoolsjar
https://github.com/thickpaddy/jenkins_campfire_plugin/issues/12
http://stackoverflow.com/questions/10812668/unable-to-locate-the-javac-compiler
http://stackoverflow.com/questions/5730815/unable-to-locate-tools-jar

and updated my plugin config to include the tools as systemPath dependency

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <configuration>
        <factory>com.infonova.om.il.apt.Factory</factory>
        <showWarnings>true</showWarnings>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.8</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
    </dependencies>
</plugin>

but the problem presists. My maven version details are

pauloconnell@pauloconnell-HP-ZBook-15:~/$ mvn -version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IE, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-63-generic", arch: "amd64", family: "unix"

I believe i jave the correct JAVA_HOME and PATHS set. Any ideas?

Holger
  • 285,553
  • 42
  • 434
  • 765
emeraldjava
  • 10,894
  • 26
  • 97
  • 170
  • The 'java-8-oracle' is a full jdk and jre install. The jar does exist at '/usr/lib/jvm/java-8-oracle/lib/tools.jar' if your running ubuntu. – emeraldjava Oct 01 '15 at 11:21
  • 1
    Ok, forget my last comment. The problem is that it is searching for the **apt** compiler, which does not exist anymore. That’s the problem with using non-standard APIs. `apt` has been integrated into the `javac` compiler and can be used with the standardized compiler API. If that problem is caused by maven/apt-maven-plugin, you’ll need an update. – Holger Oct 01 '15 at 11:37
  • Why `${java.home}/../lib/tools.jar` and not `${java.home}/lib/tools.jar` ? – Eldad Assis Oct 01 '15 at 12:03
  • 1
    @holger - yes, it seems in Java 8 the APT compiler is moved to javac and cannot be called via the tools.jar as in previous versions. – emeraldjava Oct 01 '15 at 12:41
  • @Eldad AK: `java.home` points to the jre that is embedded in the jdk in this case. The `tools.jar` resides in the `jdk/lib`, not in the `jdk/jre/lib`. I’m looking excitedly towards Java 9, where `tools.jar` is supposed to vanish entirely… – Holger Oct 01 '15 at 13:09
  • I have raised an issue for this problem - https://github.com/mojohaus/mojohaus.github.io/issues/12 – shaunthomas999 May 12 '16 at 10:48

0 Answers0