728x90 AdSpace

Wednesday, 21 June 2017

How to configure Maven to use Java 8

In pom.xml, defined this maven.compiler.source properties to configure Maven to use Java 8 to compile the project.

Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.

For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:

 

  [...]
  
    1.8
    1.8
  
  [...]


or configure the plugin directly:

 

  [...]
  
    [...]
    
      
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.1
        
          1.8
          1.8
        
      
    
    [...]
  
  [...]


Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE

Annamalai Thangaraj

Annamalai is working as Technical Lead in Leading Telecom company with 5+ years experience in Identity and Access Management , Telecom and Networks, BigData, Java, Spring, Struts, Hibernate, AngularJS, and Enterprise Web Application Development.

Website: Java Tutorials Corner

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: How to configure Maven to use Java 8 Rating: 5 Reviewed By: Annamalai Thangaraj