Missing tools.jar in local repository breaks m2ecl

2020-02-08 05:34发布

The problem I'm experiencing is that eclipse can't resolve any of the dependencies of my project. This causes problems because even though the dependencies seem to work alright when coding (I get autocompletion) I still get a huge list of errors referring to missing artifacts.

When filtering these, I found the following:

The container 'Maven Dependencies' references non existing library '/home/[...]/.m2/repository/com/sun/tools/1.5.0/tools-1.5.0.jar'

It seems that this dependency was introduced by struts2, who have a profile set up as follows in their pom:

<dependency>
    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    <version>1.5.0</version>
    <scope>system</scope>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

That systemPath resolves and so I don't see a reason why this would be causing trouble. In any case, is there a way to tell eclipse that this m2eclipse dependency is a system dependency that is not found in the local repository?

17条回答
狗以群分
2楼-- · 2020-02-08 06:20

You need to verify that Eclipse is using JDK installs.

In Eclipse IDE go to Window / Preferences / Java / Installed JREs point to a JDK installation.

For example: C:\Program Files (x86)\Java\jdk1.6.0_37

查看更多
Viruses.
3楼-- · 2020-02-08 06:20

In each project you import into Eclipse, Eclipse makes some files on filesystem - .project, .classpath, a folder .settings,. It seems that Eclipse doesn't update these correctly.

Delete these and import them again.

Clearly, this workaround won't work if this is your 1st import and you already have obtained some issues. Than have a look here Maven2: Missing artifact but jars are in place

查看更多
劳资没心,怎么记你
4楼-- · 2020-02-08 06:21

I also had a similar issue and fixed it the following way. Go to lib directory of JDK installed path in command prompt. Execute the below command to install to install tools.jar.

$mvn install:install-file -DgroupId=sun.jdk -DartifactId=tools \
     -Dpackaging=jar -Dversion=1.6 -Dfile=tools.jar
查看更多
对你真心纯属浪费
5楼-- · 2020-02-08 06:22

I eventually found what was causing it. Seemingly it's a bug in m2eclipse when you are using maven1 repositories. I still had the java.net maven1 repository in my pom; after disabling it everything works again. A very annoying problem to track down because in the end it had nothing to do with finding the tools jar.

查看更多
何必那么认真
6楼-- · 2020-02-08 06:25

As strange as this may sound, I solved this issue by just re-synchronizing with the SVN repository.

The thing is, I took the entire workspace from another PC, so when I imported the maven project using the m2e plugin, maybe some dependencies didn't synchronize correctly.

I'm posting this just in case someone is desperate with this error and trying all possibilities.

查看更多
别忘想泡老子
7楼-- · 2020-02-08 06:29

I had the same problem - Eclipse couldn't find a tools.jar. As I found out the reason is that Eclipse used a JRE and not a JDK. You have to add a -vm parameter to eclipse.ini that is pointed to your JDK bin directory:
...
-vm
path_to_jdk\bin
...

This should fix the problem.

查看更多
登录 后发表回答