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:10

I had the same issue several times and I could fix it following two steps:

  1. I added "-vm C:\\bin" to eclipse.ini or to the link from which I run eclipse.
  2. After having this problem many times, I began to suspect that there may be some m2eclipse cache that is reloaded after some time (one day or so), so I tried a weird solution: temporarily changing the computer time to the following day and restarting Eclipse or closing/cleaning the project and.... IT WORKED!!!

I could repeat the process several times successfully.

A more elegant solution (I haven't had the chance to try it yet), might be to clear m2eclipse caches mentioned at https://stackoverflow.com/a/16444984.

Hope this will help anyone.

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

I had this issue, but I have fixed by using the steps below:

Case1:

Eclipse by default pointing to JRE but eclipse maven plugin required JDK so point to JDK

Window -> Preperences -> Java -> Installed JREs

change it to JDK

Follow the steps to change to JDK from JRE

  1. In the Eclipse IDE go to: Window… Preferences… Installed JREs
  2. Select defaulted JRE and click on Edit.
  3. Click on Add External Jar
  4. I found tools.jar in “C:\Program Files\Java\jdk1.6.0_22\lib” and added.

Now I can build my project without any issue. Is this the correct way to solve this issue?

查看更多
聊天终结者
4楼-- · 2020-02-08 06:11
<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
 </dependency>

Just add this. It will work.

查看更多
聊天终结者
5楼-- · 2020-02-08 06:13

I was facing the same problem and needed to do the following things

  • Added -vm path/to/jdk/bin in eclipse.ini file
  • Clean the existing workspace and reload the project.

It worked for me seamlessly.

Its worth to add that, in my eclipse.ini file I had to add the -vm ... lines at the top of the file. like

-vm
C:\Program Files\Java\jdk1.6.0_27\bin
... ... ...

Make sure that, -vm option is placed before -vmargs as everything after -vmargs is passed directely to vm and selecting a particular is depend on -vm option.

查看更多
Emotional °昔
6楼-- · 2020-02-08 06:14

excludes tools jar from the struts dependency.

<exclusions>
    <exclusion>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
    </exclusion>
</exclusions>
查看更多
Lonely孤独者°
7楼-- · 2020-02-08 06:17

Download http://repository.ops4j.org/maven2/tools/tools/1.5.0/ and put the jar in the C:\Documents and Settings\Administrador\.m2\repository\com\sun\tools\1.5.0. Good luck.

查看更多
登录 后发表回答