您的位置:首页 > 编程语言 > Java开发

让Maven支持Java5.0

2009-04-21 09:50 148 查看
  本以为本地JDK版本为1.5,Maven就会默认支持1.5的功能,但此想法错了,刚在用Maven编译代码时,因代码中有泛型,结果Maven报错误:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SimpleWeather
[INFO]
[INFO] Id: org.yuzp:SimpleWeather:jar:1.0
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 5 source files to E:/workspace/SimpleWeather/target/classes
[ERROR]

Mojo:

org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile

FAILED for project:

org.yuzp:SimpleWeather:jar:1.0

Reason:

E:/workspace/SimpleWeather/src/main/java/org/yuzp/demo/maven/simpleweather/YahooParser.java:[37,19] generics are not supported in -source 1.3
(try -source 1.5 to enable generics)
Map<String, String> uris = new HashMap<String, String>();

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run with the -e flag
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILED
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Apr 21 09:51:35 CST 2009
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------


看来Maven默认不支持Java1.5呢,在网上找了半天原因,最后发现是需要在pom.xml中手动指定JVM的版本:

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


Maven会有这么不智能?还是我没找到让Maven自动识别JDK的方法? 哪位高手知道的麻烦告诉一声哟~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: