How do I figure out and change which version of Java Maven is using to execute?

mvn -version will output which java it's using. If JAVA_HOME is set to a valid JDK directory and Maven is using something else, then most likely someone has tampered with the way that Maven starts up.


You will need to configure maven-compiler-plugin to use 1.6 source and target parameters ( by default it is 1.5 ).

This is the best done in your project's parent pom in <pluginManagment> section ( but you can always configure it per individual projects of course ).

  <build>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>

          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

mvn -version tells you what compiler Maven is using, so this answers the question unless your POM specifies override values for the versions to be used.

Here's the easiest way to specify the overrides in pom.xml:

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

Alternatively, the maven-compiler-plugin can be specified more explicitly. In that case, look at the <source> and <target> values associated with the plugin.

Both of these options are described here.

If your POM has a <parent>, then you need to check that as well (recursively).

Note: When source and target are specified, these values are passed as command-line options to the compiler. Using this feature, you can compile or run against earlier Java versions than the compiler's nominal value.

Tags:

Java

Maven