2

how to force maven to compile 1.6 compatible source

i made web-app project with maven in eclipse. change web.xml to use 3.0 version -> then update configuration and now i cant start tomcat. I found that i have to force maven to compile source 1.6 compatible and i have to add

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
    <source>1.7</source>
    <target>1.7</target>
    <showDeprecation>true</showDeprecation>
    <showWarnings>true</showWarnings>
    <executable>${env.JAVA_HOME_7}/bin/javac</executable>
    <fork>true</fork>
</configuration>

but effective pom in eclipse is not editable

so is there a maven compatible with eclipse or any other way to force maven to compile source 1.6 version?

Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
simar
  • 1,782
  • 3
  • 16
  • 33

3 Answers3

4

You have it there. Just put 1.6 instead of 1.7:

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

see: http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

I would also avoid additional configuration if not needed.

wemu
  • 7,952
  • 4
  • 30
  • 59
1

EDIT:

Just use instead of 1.7 java 1.6.

EDIT2:

Your version:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
      <executable>${env.JAVA_HOME_7}/bin/javac</executable>
      <fork>true</fork>
    </configuration>
</plugin>

Should be:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
      <executable>${env.JAVA_HOME_7}/bin/javac</executable>
      <fork>true</fork>
    </configuration>
</plugin>
Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
1

Just for clarification :

In your project POM, you don't actually write all your configuraton, but override (and eventually add features to) the default configuration.

"Effective POM" in Eclipse shows you the result of it, so indeed this is not editable.

However, if you add some configuration in your POM (like waht is proposed in the other answers), it will override the default settings. It will be used as is, and will shown in the "Effective POM".

Samuel EUSTACHI
  • 3,116
  • 19
  • 24