34

I made a new struts project in eclipse using the struts2-archtype-starter.

A few errors where in my project already before doing anything. Solved most of them but there is 1 the still give me some problems.

Missing artifact com.sun:tools:jar:1.5.0:system pom.xml

I tried to add the tools.jar to my repository manually but that didn't solve the issue.

My pom looks like this

<?xml version="1.0" encoding="UTF-8" ?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.divespot</groupId>
    <artifactId>website</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>E-Divespot diving community</name>
    <url>http://www.e-divespot.com</url>
    <description>A website to support divers from all around the world.</description>

    <dependencies>
        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <!--  Struts 2 -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.0.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-sitemesh-plugin</artifactId>
            <version>2.0.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.0.11.2</version>
        </dependency>

        <!-- Servlet & Jsp -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jakarta Commons -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- Dwr -->
        <dependency>
            <groupId>uk.ltd.getahead</groupId>
            <artifactId>dwr</artifactId>
            <version>1.1-beta-3</version>
        </dependency>
    </dependencies>

    <build>
      <finalName>website</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                   <source>1.6</source>
                   <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.5</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Mark Baijens
  • 13,028
  • 11
  • 47
  • 73
  • Possible duplicate of [Missing artifact com.sun:tools:jar](http://stackoverflow.com/questions/8375423/missing-artifact-com-suntoolsjar) – eis Apr 11 '17 at 09:34

9 Answers9

45

The error you are seeing is probably because you dont have your JAVA_HOME path set up correctly. Are you seeing something like C:\{directories to jre}\..\lib\tools.jar?

You can have eclipse start up using your built in JDK by altering the eclipse.ini and adding something like

-vm
C:\{directories to JDK}\bin\javaw.exe

What I have learned is that eclipse by default will use your system jre to start eclipse. You probably have seen a message when starting eclipse similar to "Eclipse is running under a JRE and m2eclipse requires a JDK some plugins will not work"

If you go to (in eclipse) Help -> Installation Details and look for a -vm you will probably see it pointing to somewhere that does not have the path structure that it is expecting.

Note: For whatever reason when I encountered this issue java.home in maven was evaluated from where eclipse was launched from. So when it tries to pull the tools.jar from what it sees as java.home it may not be what you actually set as JAVA_HOME as an env/system variable.

John Vint
  • 39,695
  • 7
  • 78
  • 108
  • 3
    You want to make sure its placed in the right position before -vmargs and you may need to put quotes around the location (ie Program Files...). I would spend time trying to get this to work because im confident it will resolve your issue. – John Vint Apr 22 '11 at 14:42
  • No problem! I had to spend some time on this myself to get it to work :) – John Vint Apr 22 '11 at 14:51
  • Thanks, that saved me some trouble. – Will Oct 30 '12 at 10:30
  • 1
    +1. Saved me some time. Just a quick note: you might need to clean your workspace before the setting actually works. – Viccari Nov 08 '12 at 11:25
  • Had a similar problem today, after some java update, I think. Changing the eclipse.ini helped, but what I changed was `-Dosgi.requiredJavaVersion=1.6` to `-Dosgi.requiredJavaVersion=1.7` – kratenko Apr 29 '14 at 09:53
  • I found that it was important to have the property spread over two lines (as in the example above), having declared on a single line caused Eclipse to ignore the setting. – Ben Dec 14 '15 at 08:40
10
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>
</dependency>
Thamizharasu
  • 301
  • 3
  • 13
3

Need to add another answer. After upgrading m2e to 1.4.20130601-0317 the error came back. Again, none of the proposed solutions worked including the one I just proposed. Eventually, I found the culprit: including org.htmlparser:1.6 had an implicit dependency on tools.jar. No idea why deleting the installed jre's helped with the older m2e (1.0.something). Now the solution is to exclude tools.jar:

    <dependency>
        <groupId>org.htmlparser</groupId>
        <artifactId>htmlparser</artifactId>
        <version>1.6</version>
        <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>
    </dependency>
mplwork
  • 1,120
  • 10
  • 21
3

You can't use tools.jar from a repository.

Sadly, something in your dependency tree thinks that you can. So, you have to use an 'excludes' to get rid of the existing dependency, and then replace it with the following.

If you make the version in the below match that in the error message, you might not need the 'excludes'.

You need:

  <profiles>
    <profile>
      <id>default-tools.jar</id>
      <activation>
        <property>
          <name>java.vendor</name>
          <value>Sun Microsystems Inc.</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>whatever</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>

bmargulies
  • 97,814
  • 39
  • 186
  • 310
1

Having had the same problem recently none of the above solutions worked for me. I came across http://blog.samratdhillon.com/archives/598 and figured this to be the Eclipse bug mentioned there.

I had to delete all installed jre's from Eclipse's configuration (Window -> Preferences -> Java -> Installed JREs) and only keep exactly one jdk. After that maven worked just fine without any modification to eclipse.ini or anything else. This is with Ecplise Indigo Service Release 1.

mplwork
  • 1,120
  • 10
  • 21
0

The example of eclipse.ini:

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm
C:\Java\JDK\1.6\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx1024m

-vm value: Linux Example:

-vm
/opt/sun-jdk-1.6.0.02/bin/java

From enter link description here

VSE
  • 43
  • 6
0

Confusingly the ${java.home} property actually will resolve its value from the JRE_HOME environment variable.

http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide (search for java.home)

If you don't want to change JAVA_HOME to the jre root then create the JRE_HOME variable instead.

0

The Main Problem is that the mavan can not fine the tool.jar. so this problem occurs u just add tool.jar file in your project .The Tool.jar present in you java software C:\Program Files\Java\jdk1.6.0_14\lib
try this code i hope you run successfully http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 Strust2Testing Strust2Testing 0.0.1-SNAPSHOT war org.apache.struts

        <artifactId>Struts2-core </artifactId>
        <version>2.3.15.1</version>
        <exclusions>
    <exclusion>
        <artifactId>tools</artifactId>
        <groupId>com.sun</groupId>
    </exclusion>
</exclusions>
    </dependency>
</dependencies>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

-1

sudo apt-get install openjdk-7-source