2015-05-09 92 views
3

我在我的Project中更改了使用的java版本。現在我正在使用lambda表達式。在java中構建maven程序集8

如果我編譯ith IDE(IntelliJ),它運行良好。但是當我用maven:assembly編譯時,它失敗了。

這裏的輸出:

[ERROR] ...../commands/parser/CommandParser.java:[141,73] lambda expressions are not supported in -source 1.5 
[ERROR] (use -source 8 or higher to enable lambda expressions) 

和我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.lefrantguillaume</groupId> 
<artifactId>ServerTinyTank</artifactId> 
<packaging>jar</packaging> 
<version>1.0-SNAPSHOT</version> 
<url>http://maven.apache.org</url> 

<dependencies> 
    <dependency> 
     <groupId>com.esotericsoftware</groupId> 
     <artifactId>kryonet</artifactId> 
     <version>2.22.0-RC1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.9</version> 
    </dependency> 

    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>1.9</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-json</artifactId> 
     <version>1.9</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.json-simple</groupId> 
     <artifactId>json-simple</artifactId> 
     <version>1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>args4j</groupId> 
     <artifactId>args4j</artifactId> 
     <version>2.32</version> 
    </dependency> 


</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
        <manifest> 
         <mainClass>com.lefrantguillaume.Main</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

回答

6

據我所見,你從未設置過${java.version}。而且,你不會在編譯器目標中設置該變量。

這應該是什麼樣子:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.lefrantguillaume</groupId> 
    <artifactId>ServerTinyTank</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <url>http://maven.apache.org</url> 

    <properties> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.esotericsoftware</groupId> 
      <artifactId>kryonet</artifactId> 
      <version>2.22.0-RC1</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-server</artifactId> 
      <version>1.9</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>1.9</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-json</artifactId> 
      <version>1.9</version> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.json-simple</groupId> 
      <artifactId>json-simple</artifactId> 
      <version>1.1</version> 
     </dependency> 
     <dependency> 
      <groupId>args4j</groupId> 
      <artifactId>args4j</artifactId> 
      <version>2.32</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
        <archive> 
         <manifest> 
          <mainClass>com.lefrantguillaume.Main</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 
+0

任職:d!沒有注意到編譯器插件。我也錯過了。謝謝 ! – Sw0ut

0

這應該做的伎倆

<source>1.8</source> 
<target>1.8</target> 

你在哪裏定義你的屬性?

1
  <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin>