2015-06-18 8 views
5

Erhalte einen Fehler mit Maven und Java 8 (jdk1.8.0_45). Dieses Problem tritt nicht mit Java 7.Maven Fehler mit Java 8

MCVE

eine Probe Maven Projekt. Zum Beispiel:

mvn archetype:create -DgroupId=testinovke -DartifactId=testinvoke 

Erstellen Sie den folgenden Inhalt in dem erzeugten App.java

package testinovke; 

import java.lang.invoke.MethodHandle; 
import java.lang.invoke.MethodHandles; 
import java.lang.invoke.MethodType; 

public class App { 

    public static MethodHandles.Lookup lookup; 

    public static class Check { 
     public void primitive(final int i){ 
     } 
     public void wrapper(final Integer i){ 
     } 
    } 


    public static void main(String[] args) throws Throwable { 
     Check check = new Check(); 

     MethodType type = MethodType.methodType(void.class, int.class); 

     MethodHandle mh = lookup.findVirtual(Check.class, "primitive", type); 
     mh.invoke(); 
    } 
} 

Kompilieren Sie das Maven-Projekt-Datei:

mvn clean compile 

Ausgabe

Holen Sie sich das folgende Fehler:

testinvoke/src/main/java/testinovke/App.java:[25,18] method invoked with incorrect number of arguments; expected 0, found 1 

Versucht es mit Maven 3.0.4 und 3.3.3. Dieses Problem tritt nicht auf, wenn ich direkt mit App.java mithilfe des Javac-Befehls kompiliere.

+0

Funktioniert hier mit Java 1.8.0_45 und Maven 3.2.3. –

Antwort

5

Add-Plugin-Konfiguration für den Compiler:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <verbose>true</verbose> 
       <fork>true</fork> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
+0

Danke das hat funktioniert! Antwort kann nicht akzeptiert werden, da stackoverflow 10 Minuten dauert! Wird später akzeptiert. – codedabbler

4

Eine andere Lösung ist das Hinzufügen dieser Eigenschaften:

<properties> 
    <maven.compiler.target>1.8</maven.compiler.target> 
    <maven.compiler.source>1.8</maven.compiler.source> 
</properties> 

zu Ihrem pom.xml, und die Plugins werden diese automatisch auswählen.

Verwandte Themen