LoginSignup
37
31

More than 5 years have passed since last update.

MavenプロジェクトでJDKが1.5になってしまう問題を解決する設定

Posted at

問題

EclipseでMavenプロジェクトを作成した場合、デフォルトでJRE System Libraryが1.5になる。
JDK1.7を利用して開発するので、JRE System Libraryを1.7にしたい。
プロジェクトのプロパティでビルドパスに1.7を指定すれば、一旦解決しているように見えるが、
「Maven > プロジェクトの更新」をすると、また1.5に戻ってしまう。

解決策

デフォルトが1.5になってしまうこと自体を変更する方法はわからないが、pom.xmlで明示的にビルドするJDKを指定すれば解決する。
例えば、以下のように記述する。

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.sample</groupId>
    <artifactId>foo</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

37
31
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
31