2013-06-25 26 views
11

IntelliJ 12.1.4とJava 7を使用してMaven 3.0.5でjarを作成しようとするとエラーが発生します。プロジェクトを実行できます私はそれをパッケージ化しようとすると、私は次のエラーが発生します。Mavenがエラーを返しました:-sourceでtry-with-resourcesがサポートされていません1.5

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <descriptorRefs>jar-with-dependencies</descriptorRefs> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

とエラーは、次のとおりです:

SonatypeMaven By Exampleから取られた)私のPOMの関連セクションはある

[ERROR] ...[33,55] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[207,7] error: try-with-resources is not supported in -source 1.5 
[ERROR] ...[73,52] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[129,40] error: multi-catch statement is not supported in -source 1.5 
[ERROR] ...[44,6] error: try-with-resources is not supported in -source 1.5 
[ERROR] ...[28,39] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[31,7] error: try-with-resources is not supported in -source 1.5 
[ERROR] ...[38,6] error: try-with-resources is not supported in -source 1.5 
[ERROR] ...[34,41] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[77,43] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[84,6] error: try-with-resources is not supported in -source 1.5 
[ERROR] ...[281,38] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[13,55] error: diamond operator is not supported in -source 1.5 
[ERROR] ...[155,7] error: try-with-resources is not supported in -source 1.5 

は、どのように私は、ソース1.7を使用するようにMavenを得ることができますか?

+0

Mavenではこのエラーは発生しません。 Javaコンパイラはこれを行います。 – EJP

+0

@EJPこの問題は、IDEAではなく、Mavenでコンパイルするときにのみ現れます。そのため、Mavenが疑わしいのです。ソースレベルのプロパティをPOMに追加すると、そのエラーが解決されました。これは、Mavenが問題の原因でもあることを示しています。それは、コンパイラを症状ではなく、原因にします。 –

+0

コンパイラがバージョン7のときは、1.5(またはその5!)がデフォルトであり、7ではないことが完全にわかります。新しいバージョンではあまり信頼できません。 –

答えて

38

あなたがそれを実行したときに、あなたのjarファイルがno main manifest attributeを与えるだろうが、あなたが正常にjarファイルを構築することができ、それらの行を追加した後、言語レベルに

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

を設定するには、POMに次の行を追加し、最初の部分に答えるためにエラー。

これはどちらか、これを修正し、実行可能jarファイルを作るためにjava -cp app.jar com.somepackage.SomeClass

かのように実行することによって固定することができ、

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>copy-dependencies</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${project.build.directory}/lib</outputDirectory> 
         <overWriteReleases>false</overWriteReleases> 
         <overWriteSnapshots>false</overWriteSnapshots> 
         <overWriteIfNewer>true</overWriteIfNewer> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib/</classpathPrefix> 
         <mainClass>fully.qualified.main</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

のようなあなたのポンポンの外観を作るこのPOMは、コピーしてjar-with-dependencies descriptorRefといくつかの問題を克服ビルドディレクトリへの依存関係、および含まれているライブラリでのjarファイルの作成

ありがとうございました@André Aronsen彼のポン解答です。

重要なマニフェストエラーはありません。この問題については多くの記事がありますが、いくつかの解決策は機能しますが、一部の問題はありません。このソリューションは私のために働くので、私は完了のためにこの投稿にそれを含めました。

Java 7、Maven 3.0.5およびJetBrains IntelliJ IDEA 12.1.4 Ultimateでテスト済みです。

+0

POMとは何ですか?私は誰もが答える時にそれを見つけたでしょう... – Vozzie

+0

POMはあなたのmaven設定ファイルです –

+0

ありがとう、魅力的なように働いた –

関連する問題