使用Maven一年有余,却总是被两则不起眼的编译信息困扰,终想查明,这两则信息如下:
- [INFO] Using Eclipse Workspace: D:\maven\workspace
- [WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre7
- [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6
始终搞不懂为何出现这两则信息,上午终于搞懂,其实一切还是从编译时自动转换了JRE说起。
每次编译完Maven项目,其在Eclipse中Jre System Library总是会变成JavaSE-1.6,而不是自己设置的JRE,遂尝试在Google下寻找答案,找到了两个URL如下
How to make Maven use Eclipse workspace default JRE?
http://stackoverflow.com/questions/12322202/how-to-make-maven-use-eclipse-workspace-default-jre 大名鼎鼎的stackoverflow,还有一则是在maven官网上找到的,链接如下
The JDK is being used is different than expected
http://maven.apache.org/plugins/maven-eclipse-plugin/trouble-shooting/jdk-being-used-is-different-than-expected.html 于是慢慢尝试如何消除掉这两则看似正常的不正常INFO/Waring,分两步
1:在stackoverflow查到Eclipse的JRE指向可能存在问题,遂检查之,发现JRE_HOME指向的是JRE目录,改成JDK目录
2:将maven的编译plugin的与机器的JDK版本对应,比如我在项目中写的1.6,而机器安装的是JDK1.7
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
设置后编译出现如下信息
- [INFO] Using Eclipse Workspace: D:\maven\workspace
- [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER