【问题标题】:Maven doesnt use specified source and target settingsMaven 不使用指定的源和目标设置
【发布时间】:2013-01-16 15:40:08
【问题描述】:

我正在尝试使用 maven 构建一个 java 项目。在项目根目录的 pom.xml 文件中,我有以下几行:

  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>                                                                             
    <target>1.6</target>
    <debug>true</debug>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>

但是当我尝试使用mvn -DskipTests -U install 构建时,我得到以下error: static import declarations are not supported in -source 1.3

maven 没有使用我在 pom 中指定的源和目标 (1.6)。

java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

mvn --version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-21-generic", arch: "amd64", family: "unix"

uname -a
Linux ubuntu 3.5.0-21-generic #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

maven 是否可以从其他任何地方获取其默认源和目标设置?为什么不使用 pom 中的设置?

这里是 maven 在调试模式下运行时的错误消息的 sn-p:

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
 [ERROR] /path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3

 [ERROR] -> [Help 1]                                                                                
 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins: maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
 /path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3

【问题讨论】:

  • 你安装了 JDK 6 吗?
  • 在调试模式下运行时能否粘贴输出的相关 sn-p - 即mvn -X -DskipTests -U install
  • 我看到 maven-compiler-plugin 的 2.0.2 版本正在被使用。指定最新版本的插件3.0 并重试怎么样?
  • 请检查 settings.xml 中的配置文件,可能还有其他配置。
  • 你可以试试mvn help:effective-pom - 这将确认使用的版本。还运行 mvn help:all-profiles 以查看存在哪些配置文件,如果其中一个配置文件覆盖 pom 插件配置,请运行 mvn help:active-profiles

标签: java maven


【解决方案1】:

尝试使用以下属性设置源级别和源编码:

<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

【讨论】:

    【解决方案2】:

    尝试清除本地 Maven 存储库并再次运行构建(也许,也尝试使用“-o”选项运行它)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-18
      • 2023-04-07
      • 1970-01-01
      • 2011-07-10
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多