由于最近公司人手增多,开发和部署已经逐步分离,为了方便部署人员打包部署,开发人员也逐步告别通过在 Eclipse 中 export 打包的方式,而习惯了使用 maven 进行打包。
在使用 mvn package 打包时,控制台报出如下错误信息,打包失败:
[INFO] BUILD FAILURE
[INFO]------------------------------------------------------------------------
[INFO] Total time: 3.993 s
[INFO] Finished at:2015-07-21T16:34:14+08:00
[INFO] Final Memory: 8M/121M
[INFO]------------------------------------------------------------------------
[ERROR] Failed to execute goalorg.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile)on project rumorsend_web: Fatal error compiling: tools.jar not found:C:\Program Files\Java\jre1.8.0_45\..\lib\tools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of theerrors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch toenable full debug logging.
[ERROR]
[ERROR] For more information about theerrors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
其中,最重要的错误信息显然是
tools.jar notfound: C:\ProgramFiles\Java\jre1.8.0_45\..\lib\tools.jar
拿这个信息各种搜索引擎搜了一下,得到的结果基本都是需要需要修改 Java库,由 jre 目录改为 jdk 目录,可是看来看去在 Eclipse 中都是图-1所示的结果:
图-1
而 jdk1.8.0_u45 在当时 install 时确实也指向都是 jdk 目录,反反复复在这块做了各种各样的修改,结果在 mvn package 时还是报出了同样的错误,后来一想,maven 打包和 Java 编译使用的 jdk 可能不同,于是发现果然如此,如图-2所示:
图-2
于是修改 maven 打包时使用的 jdk,再次 mvn package,终于出现了久违的
[INFO] BUILDSUCCESS
完。
转载于:https://blog.51cto.com/xitongjiagoushi/1677352