views:

67

answers:

2

I am trying to compile a maven project, the source code uses Generics and other featuers of Java 1.5, thus causing my build to fail

In my POM.xml I have configured the build configuration against 1.5 for the source and target properties, but this doesn't solve my issue

Is my POM.xml correct, or am I missing something?

Thanks

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    <modelVersion>4.0.0</modelVersion>
    <name>MyClass</name>
    <groupId>uk.co.mydomain</groupId>
    <artifactId>MyClass</artifactId>
    <version>1.0</version>

    <build>
      <finalName>MyClass</finalName>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <descriptors>
              <descriptor>src/main/resources/dist.xml</descriptor>
            </descriptors>
            <archive>
              <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
            </archive>
          </configuration>
        </plugin>
      </plugins>
    </build>

    <repositories>
        <repository>
            <id>sun-repo-2</id>
            <url>http://download.java.net/maven/2/&lt;/url&gt;
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

Output when attemtping to build

generics are not supported in -1.3 (use -source 5 or higher to enable generics)
+3  A: 

You have to set some properties to compile with java 1.5

<properties>
    <!-- maven-compiler-plugin configuration -->
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
</properties>
Colin Hebert
This will not configure the compiler plugin. It will define some properties only.
khmarbaise
Some properties used by the compiler plugin : http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source
Colin Hebert
This is nice, I never thought of that, although it should be obvious. +1
seanizer
+7  A: 

You configured the assembly-plugin with some information about source/target but to configure the compiling you need to configure the compiler-plugin in the correct way.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.1</version>
  <configuration>
    <source>1.5</source>
    <target>1.5</target>
  </configuration>
</plugin>
khmarbaise