Annotations are not supported in -source 1.3 – Maven

Problem

Building a Maven project, hit following annotation error message in Maven output console.


[INFO] Compilation failure
E:\workspace\serlvetdemo\src\main\java\com\mkyong\AppServletContextListener.java:
[8,2] annotations are not supported in -source 1.3 
(use -source 5 or higher to enable annotations)
        @Override

Solution

Maven default is using JDK1.3 for the project compilation, building or packaging (mvn compile, install). Since JDK1.3 is not support annotation, if your project has annotation, you need to configure your Maven to use the latest JDK version. The solution is very simple, just include the Maven compiler plugin and specify the JDK version. For example,


<project ....>
 <build>
  <plugins>
	<plugin>
		<artifactId>maven-compiler-plugin</artifactId>
		<version>2.3.2</version>
		<configuration>
			<source>1.6</source>
			<target>1.6</target>
		</configuration>
	</plugin>
   </plugins>
  </build>
</project>

Above declaration tell Maven to use JDK 1.6.

Reference

  1. http://maven.apache.org/plugins/maven-compiler-plugin/

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
12 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
12 Comment authors
DucatistaAnooshTommyGururajJuan Pablo Recent comment authors
newest oldest most voted
Ducatista
Guest
Ducatista

How do I do this on intellij? Where can I find that xml file?

Anoosh
Guest
Anoosh

awesome

Tommy
Guest
Tommy

Thanks man! This was a big help!

Gururaj
Guest
Gururaj

Thanks for all the suggestion, tutorials and code that you share. Really great help to whole world. Appreciate your time and efforts

Juan Pablo
Guest
Juan Pablo

Mkyong you are the best…

Adrian Klimczak
Guest
Adrian Klimczak

Thx man!!

news
Guest
news

I as well as my buddies appeared to be checking out the excellent hints found on your web site and suddenly developed a horrible feeling I had not expressed respect to the blog owner for those strategies. All of the women were as a result warmed to study all of them and already have definitely been using them. I appreciate you for being simply helpful and also for making a decision on such fantastic areas millions of individuals are really desperate to know about. My very own honest regret for not expressing gratitude to sooner.

michoser
Guest
michoser

sometimes this site seems more powerful than googleit principle :)

jeremie
Guest
jeremie

Thanks.
I struggled with that for more than a day. This really helped!

Clem
Guest
Clem

Thank you,
it solves the problem with my project which uses annotations and need JDK 1.5

Shirish
Guest
Shirish

Incredibly annoying problem. Thanks! :)

Daniel - velaia GmbH
Guest
Daniel - velaia GmbH

Hi, this helped with an issue I had. Locally everything worked fine, but after committing to Hudson build server the project build failed. Thanks for posting and I hope the “hudson” keyword will help people find the solution here faster.

Tommy
Guest
Tommy

Thanks man! This post was a great time saver for me.