Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

When running our Maven build, a member of my team gets a NoSuchMethodError in one of the dependant plug-ins when executing. However, when we run java -version from her command line, it indicates Java 1.6.0_26. The error obviously seems to be screaming that Maven is using Java 5.

How do I figure out and change what version of Java is being used by Maven?

3 potentially important notes:

  1. This is executed at the command line, not using Eclipse plugin
  2. JAVA_HOME is set to a Java 1.6 JDK
  3. Using Maven 2.2.1
like image 948
shsteimer Avatar asked Aug 11 '11 21:08

shsteimer


People also ask

How do I know what version of Java Maven is using?

Before moving on, we can check the default JDK version of Maven. Running the mvn -v command will show the Java version in which Maven runs.

How do I set Java version to Maven?

You can set the JAVA_HOME parameter just before you start maven (and change it back afterwards if need be). You could also go into your mvn (non-windows)/ mvn. bat / mvn. cmd (windows) and set your java version explicitly there.


2 Answers

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.

like image 185
Ryan Stewart Avatar answered Sep 30 '22 09:09

Ryan Stewart


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> 
like image 43
Alexander Pogrebnyak Avatar answered Sep 30 '22 07:09

Alexander Pogrebnyak