如何强制maven将我的项目打包为1.5? [英] How can I force maven to package my project against 1.5?

查看:116
本文介绍了如何强制maven将我的项目打包为1.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译maven项目,源代码使用Generics和Java 1.5的其他特性,从而导致我的构建失败

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

在我的<$ c中$ c> POM.xml 我已经为源和目标属性配置了针对1.5的构建配置,但这并没有解决我的问题

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

我的 POM.xml 是正确的,还是我错过了什么?

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

谢谢

<?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">
    <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/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

attentping to build时的输出

Output when attemtping to build

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


推荐答案

您为assembly-plugin配置了一些有关源/目标的信息,但是要配置编译所需的配置 compiler-plugin 以正确的方式。

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>

更新:
这应该与maven-enforcer结合使用-plugin强制使用JDK 1.5而不是仅使用javac的source / target选项。

Update: This should be combined with maven-enforcer-plugin to force really using of JDK 1.5 instead of only using source/target option of the javac.

这篇关于如何强制maven将我的项目打包为1.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆