【问题标题】:Maven - use -source 5 or higher to enable... while building the projectMaven - 在构建项目时使用 -source 5 或更高版本来启用...
【发布时间】:2013-05-25 05:02:48
【问题描述】:

我从我们的 svn 下载了一个项目,现在我正在尝试使用 Maven 构建它(mvn clean install...我的 maven 是 Apache Maven 3.0.4)。不幸的是,当我尝试构建时,会出现以下错误。奇怪的是,它报告了一些关于 Java 1.3 版的信息(我认为),我当然没有在我的笔记本电脑上安装它。我将JAVA_HOME 设置为 JDK 1.7,我的 javac 也在 1.7 版本中......

请问你知道问题出在哪里吗?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project irapi: Compilation failure: Compilation failure:
[ERROR] /home/jan/nutch/src/plugin/irapi/src/main/java/cz/cvut/fit/linkedtv/irapi/rest/MediaServer.java:[21,1] error: **annotations are not supported in -source 1.3**
[ERROR] 
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/jan/nutch/src/plugin/irapi/src/main/java/cz/cvut/fit/linkedtv/irapi/solr/SolrQueryResponseConvertor.java:[35,26] error: **for-each loops are not supported in -source 1.3**

【问题讨论】:

  • 你是在命令行运行maven吗?在你的命令行中,当你输入java -version时它会说什么?
  • 是的,从命令行。它说 jan@jan:~/nutch/src/plugin/irapi$ java -version java version "1.7.0_17" Java(TM) SE Runtime Environment (build 1.7.0_17-b02) Java HotSpot(TM) 64-Bit Server虚拟机(内部版本 23.7-b01,混合模式)
  • 很奇怪,也许硬编码该值会解决您的问题:maven.apache.org/plugins/maven-compiler-plugin/examples/…
  • 谢谢你,它正在工作!
  • @tieTYT 也为我工作。谢谢!

标签: maven java pom.xml


【解决方案1】:

您必须像这样为 maven-compiler-plugin 指定源配置参数:

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

有关更多详细信息,另请参阅 maven 文档中的 Setting the -source and -target of the Java Compiler

【讨论】:

  • 如果您收到(use -source 5 or higher to enable annotations),也请使用&lt;target&gt;1.5&lt;/target&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-24
  • 1970-01-01
  • 2015-05-29
  • 2020-02-08
  • 1970-01-01
  • 2018-09-29
相关资源
最近更新 更多