tags:

views:

70

answers:

3

Hi!

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!

+7  A: 

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>
javamonkey79
very good. Thanks!
artaxerxe
A: 

Add the following lines to the POM:

   <properties>
      <java.version>1.6</java.version>
   </properties>

Edit: Ah, too bad, just saw that those are custom properties... Won't work.

fgysin
Whaaaaat? Where does this comes from? And what is this supposed to do?
Pascal Thivent
bad answer! doesn't work!
artaxerxe
+3  A: 

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):

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.

seanizer
Setting the compiler level is becoming one of the memes of SO ;) (+1)
Pascal Thivent
really nice tip!
artaxerxe