1

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?

2
  • It's good that you have java 7 installed but it has nothing to do with the error. Please post your pom.xml. Apr 30, 2013 at 9:22
  • Are you using Maven 2 or 3?
    – McDowell
    Apr 30, 2013 at 9:25

5 Answers 5

8

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>

4
  • actually, he should replace all occurrences of 1.6 in this code with 1.7, but still: +1 Apr 30, 2013 at 9:25
  • I put this in the parent pom but still cannot compile Apr 30, 2013 at 9:50
  • Where have you put this in your pom.xml file and could we see the pom.xml file. Also, you may want to change source to 1.7 and target to 1.7 rather than 1.6. Apr 30, 2013 at 9:51
  • Yep. I did those changes in the first place. I put this in the parent pom and referred it from the relevant modules. Apr 30, 2013 at 9:54
0

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

0

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>
0
<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!!!

0
0
<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>

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.