Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

m2eclipse sets JDK compliance to 1.4

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?

like image 258
Jihed Amine Avatar asked Jun 13 '10 14:06

Jihed Amine


1 Answers

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.

like image 109
VonC Avatar answered Nov 20 '22 23:11

VonC