Prasad Weera
Prasad Weera

Reputation: 1299

Maven gives a java version error (ask for java 1.5) even when I have java 1.7 installed

I'm getting an error saying

(use -source 5 or higher to enable annotations) {class path} error: for-each loops are not supported in -source 1.3

when I try to compile a module using maven.

The thing is that the java version in my machine is 1.7.0_02

Can anyone suggest a solution?

Upvotes: 1

Views: 690

Answers (5)

Victor
Victor

Reputation: 781

<build>
<finalName>your project name</finalName>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
</plugins>

Upvotes: 0

tono
tono

Reputation: 1

<build>
  <pluginManagement>
      <plugins>
          <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.5</source>
                  <target>1.5</target>
                  <compilerArgument></compilerArgument>
              </configuration>
          </plugin>
      </plugins>
  </pluginManagement>

by blackpanther

this other too

<project>
   ....
   <properties>
       <maven.compiler.source>1.5</maven.compiler.source>
       <maven.compiler.target>1.5</maven.compiler.target>
   </properties>

by rzymek

all together

and clean and build the proyect and that's work fine vatos!!!

Upvotes: 0

rzymek
rzymek

Reputation: 9301

The shortest version is to set maven.compiler.source and maven.compiler.target properties in your pom.xml:

<project>
   ....
   <properties>
       <maven.compiler.source>1.5</maven.compiler.source>
       <maven.compiler.target>1.5</maven.compiler.target>
   </properties>

Upvotes: 0

Sascha
Sascha

Reputation: 1

Please, check the value of the JAVA_HOME environment variable.
For the user acc which is used by maven

Upvotes: 0

blackpanther
blackpanther

Reputation: 11486

You may want to include this in your pom.xml file as I had the same problem:

<build>
  <pluginManagement>
      <plugins>
          <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <compilerArgument></compilerArgument>
              </configuration>
          </plugin>
      </plugins>
  </pluginManagement>

Upvotes: 8

Related Questions