How do I configure Eclipse and Maven to detect jdk.tools?

北战南征 提交于 2021-01-28 01:42:41

问题


I have a maven project in Eclipse where I am using some hadoop libraries (hadoop-common, hadoop-auth, hadoop-hdfs) and these bring in a dependency on jdk.tools. When I check this project out on a different machine, it works fine, but on mine the pom.xml complains about "missing artifact jdk.tools:jdk:tools:jar:1.6". I can fix this by adding a dependency manually and specifying the file on my local drive (eg "${JAVA_HOME}/../lib/tools.jar") but I would like to understand why it works on one computer and not on another - I am assuming there is something wrong with my setup?

I have tried the following:

Made sure Eclipse is running in a JDK by adding "-vm C:\Program Files\Java\jdk1.6.0_25\bin\javaw.exe" to my eclipse.ini file. The only JRE listed under Eclipse preferences Java -> Installed JREs is the same JDK. Tried switching maven version in Eclipse preferences Maven -> Installations between "Embedded (3.0.4)", "External (3.0.4)" and "External (2.2.1)"

Maybe something I need to add/change in my maven settings.xml file?

Any suggestions would be appreciated!

FYI I am using Eclipse Java EE Juno SR1 and M2E 1.2.0.


回答1:


JAVA_HOME should point to the folder where java is installed in settings.xml file make sure you have JAVA_HOME property and it point to correct folder

${JAVA_HOME}/../lib/tools.jar is not correct. it should be ${JAVA_HOME}/lib/tools.jar, since tools.jar is under /lib folder and /lib folder is immediately under ${JAVA_HOME} folder




回答2:


I also added the following to my eclipse.ini file:

-vm
${JAVA_HOME}/bin

and that seemed to fix my problem.

Note: I am running Eclipse 4.3 (Kepler).




回答3:


Seems like there are three Options. The first two ensure that first found java is JDK's java and they result in eclipse properly translating system dependency to jar beneath JDK. The last allows a way to not require each user to run eclipse via a special manner but may have implications if your dev environment isn't 100% in sync with your production environment. If you expect jdk.tools 1.6 to be present but did your testing with 1.7 or 1.8 you might be in for a surprise.

  • via eclipse.ini

--launcher.appendVmargs -vm
c:/code/Java/jdk1.8.0_40/jre/bin/server/jvm.dll -vmargs -Dosgi.requiredJavaVersion=1.6

  • via path

set PATH=PATH-TO-JDK\bin;%PATH% PATH-TO-ECLIPSE\eclipse.exe

  • via pom

add tools.jar as jdk.tools:jdk.tools:<JDK version> to your local or private shared repo (nexus/artefactory etc) add dependency to your project



来源:https://stackoverflow.com/questions/14649986/how-do-i-configure-eclipse-and-maven-to-detect-jdk-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!