Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to change project compliance to 1.5?

Tags:

java

maven-2

I created a project with maven2 on eclipse. After I added the hibernate-annotations dependency, i was trying to create a class using hibernate annotations(@Entity, @Table...), but it was giving me this error :

Change project compliance and JRE to 1.5

I fixed it, but cannot understand why it requires this as long as my jdk is 1.6.

Thank in advance!

like image 397
artaxerxe Avatar asked Oct 29 '10 06:10

artaxerxe


2 Answers

Check that the settings for the maven compiler plugin is set to 1.5 or 1.6 as well. If I'm not mistaken maven 2 defaults to 1.4.

Something like this:

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
like image 146
javamonkey79 Avatar answered Oct 07 '22 18:10

javamonkey79


While javamonkey79's solution is the standard way to do it, there is also a property-based solution, but it's not the one fgysin suggests:

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

Reference (Maven compiler plugin):

  • <source> parameter
  • <target> parameter

BTW, the reason is that the maven compiler plugin builds a command line call to javac in which it specifies source and target version explicitly (overriding javac's default settings). And previous versions of the compiler plugin had their own defaults set to 1.3. However, starting from plugin version 2.3, 1.5 is the default source and target version.

like image 30
Sean Patrick Floyd Avatar answered Oct 07 '22 19:10

Sean Patrick Floyd