How to set specific java version to Maven/Pom

From time to time we need to specify which java we want to use when building a maven project using pom.xml.
There are mainly 2 ways to specify the same.

1. In the first process, you need to add 2 maven compiler related property providing java version.

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

2. In the second process, you need to add a plugin specifying java version.

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

FYI,
Java version can be specified using below identifier.
E.g:
1.6 – > Java 6
1.7 – > Java 7
1.8 – > Java 8
and more.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s