views:

52

answers:

2

Using eclipse 3.5, when I create a new maven project, m2eclipse automatically adds J2SE1.4 to libraries and Compiler Compliance Level to 1.4 (Project properties > Java Compiler). My JRE system library is 1.6 and my default compiler compliance level is 1.6. I don't even have 1.4 installed. Can I make m2eclipse use my default settings and prevent it from modifying project settings?

+2  A: 

The JDK compliance level is derived from the maven project, not the other way around. In other words, you need to configure the maven compiler plugin for 1.6 level compliance and then m2eclipse will derive the appropriate settings under Eclipse:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.0.2</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

The pom.xml is the master, not m2eclipse.

Pascal Thivent
Simpler explanation. +1. I was starting to worry. A maven-2 eclipse question not answered after more than 1 hour. Were in the heck is Pascal? ;)
VonC
@VonC LOL! I'm cooking :) But thanks for the +1 (and also +1 for you).
Pascal Thivent
+2  A: 

It should follow the maven-compiler-plugin configuration:

<build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>

(even if, as mentioned in this thread, it won't work for aspect-j)

This thread reminds us about the difference between m2eclipse within eclipse, and a maven script:

One thing worth to mention that this only applies to "the development mode" when m2eclipse is configuring Eclipse tools such as JDT, AJDT and WTP according to the configuration from pom.xml. This is how you normally code and debug your application, run unit tests (with Run as... / JUnit test) or run on web app server (Run as... / Server app).

However if you use Run as... / Maven build..., or create corresponding launch config from the Run/Debug menu, then you can select JVM that is used to launch Maven and all your compiler configuration will be respected in the same way it is respected in the command line.

So:

  <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <configuration>
         <verbose>true</verbose>
         <fork>true</fork>
         <executable><!-- path-to-javac --></executable>
         <compilerVersion>1.3</compilerVersion>
       </configuration>
     </plugin>
   </plugins>

m2e does not (and cannot) use external java compiler, so it will just ignore these configuration parameters. m2 only considers source/target maven-compiler-plugin parameters.

VonC