54

Today I tried the latest jdk9 Build 113 and tried to compile my project with the latest Maven 3.3.9

These are the commands (found partially via twitter)

export MVN_OPTS="-Dmaven.compiler.fork -Dmaven.compiler.executable=/somewhere/Downloads/jdk-9/bin/javac"
export JAVA_HOME="/somewhere/Downloads/jdk-9"
mvn clean install

But I get this error ... in short:

[WARNING] Error injecting: org.codehaus.plexus.archiver.jar.JarArchiver
java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(java.base@9-ea/Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(java.base@9-ea/NativeConstructorAccessorImpl.java:62)

...

at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.<clinit>(AbstractZipArchiver.java:116)
    ... 89 more
[WARNING] Error injecting: org.apache.maven.plugin.jar.JarMojo
java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(java.base@9-ea/Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(java.base@9-ea/NativeConstructorAccessorImpl.java:62)

...

at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.<clinit>(AbstractZipArchiver.java:116)
    ... 89 more

What is the correct maven configuration or parameters to use for JDK9?

$ mvn --version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: /home/somewhere/Downloads/maven
Java version: 9-ea, vendor: Oracle Corporation
Java home: /home/somewhere/Downloads/jdk-9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux",...
Naman
  • 27,789
  • 26
  • 218
  • 353
Karussell
  • 17,085
  • 16
  • 97
  • 197

6 Answers6

39

Here is the answer from one Maven PMC member (me):

No, it is not. Robert Scholte is working on it. Jigsaw and other stuff introduced a lot of changes. There is no official timeframe where full compat (Maven + official plugins) will be given.

The issue you see is actually not Maven but Plexus Archiver. Refer to their GitHub page. If you think you can add value, contact maven-dev mailing list.

Progress documentation: https://cwiki.apache.org/confluence/display/MAVEN/Java+9+-+Jigsaw

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • 3
    Ah, thanks a lot! I thought I read somewhere that this was already possible. Do you mean this github repo? https://github.com/codehaus-plexus/plexus-archiver/issues – Karussell Apr 13 '16 at 07:14
  • 1
    @Karussell Yes, that's the issue tracker. You can also try as plexus archiver snapshot manually. – Michael-O Apr 13 '16 at 08:06
16

Yes, it is ready now. Still some things in progress, but generally usable. Check out a project of mine as example.

FrisoD
  • 514
  • 4
  • 4
  • 2
    The project you had share uses compiler and jar plugins but we will be getting more plugins like jlink, jmod, jdeps. And the project does not provides examples with Automatic Modules and Unnamed Modules. I think Maven team is still working on them. – Narendran Solai Sridharan May 08 '17 at 02:38
  • Not sure what .. *but generally usable* .. means here. Too generic an answer I believe. Would ideally follow the other [one by Michael](https://stackoverflow.com/a/36584317/1746118) instead to be a reliable source. – Naman Nov 01 '17 at 16:18
  • The M2E plugin for Eclipse does not seem to be ready: https://stackoverflow.com/questions/47228377/how-to-use-maven-with-java9-0-1-and-pom-packaging-in-eclipse-oxygen-1a-release – Stefan Nov 11 '17 at 16:25
12

Update: should work without this workaround now.

The problem is already fixed from the plexus archiver team, but not yet released - thanks to Michael-O for pointing me to the right place :) !

Now there is a workaround posted from ctomc in PR 12 to use an old plexus archiver version 2.4.4.:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>                    
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-archiver</artifactId>
            <version>2.4.4</version>
        </dependency>
    </dependencies>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-archiver</artifactId>
            <version>2.4.4</version>
        </dependency>
    </dependencies>
</plugin>
Karussell
  • 17,085
  • 16
  • 97
  • 197
1

The Java doc plugin still have issues in the last version. (3.0.0.M1)

petertc
  • 3,607
  • 1
  • 31
  • 36
1

I think maven is ready now, for me the following snippet is able to tell maven to use java 9 :

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>9</source>
                <target>9</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Naman
  • 27,789
  • 26
  • 218
  • 353
  • Just the compiler plugin update doesn't justify maven's readiness and the [answer](https://stackoverflow.com/a/36584317/1746118) has a link for complete maven's readiness. Neither does the answer relates to the initial question error. – Naman Nov 01 '17 at 16:16
0

I had the same issue and the latest maven-javadoc-plugin that was published recently fixed it. Updated the dependency in the pom file to <version>3.0.0-M1</version>

Afsanehr
  • 1
  • 1