「コンパイルでのJavaバージョンを指定するには」の版間の差分
提供: tknotebook
| 24行: | 24行: | ||
</plugins> | </plugins> | ||
</build> | </build> | ||
| + | </pre> | ||
| + | |||
| + | 以上が正攻法ですが、これよりももっと簡単な方法があります。pom.xml の末尾(projectタグの内側の一番最後)に | ||
| + | |||
| + | <pre> | ||
| + | <properties> | ||
| + | <java.version>1.8</java.version> | ||
| + | <maven.compiler.target>${java.version}</maven.compiler.target> | ||
| + | <maven.compiler.source>${java.version}</maven.compiler.source> | ||
| + | </properties> | ||
</pre> | </pre> | ||
2016年10月19日 (水) 04:54時点における版
メインページ>コンピュータの部屋#Java>Maven Tips
Maven でJavaのコンパイルを行うと、Javaコンパイラのバージョンは既定で 1.5 になります。
これはもうかなり古いコンパイラなので多くの場合不適切でしょう。
maven-compiler-plugin の設定を変更するのが正攻法で、pom.xml の buildタグの中に(なければbuildタグを加え) 以下の記述を加えます。
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
以上が正攻法ですが、これよりももっと簡単な方法があります。pom.xml の末尾(projectタグの内側の一番最後)に
<properties>
<java.version>1.8</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
</properties>