Mawia
Mawia

Reputation: 4310

Struts2 exclude com.sun:tools:jar:1.5.0 required?

I am new to Struts2.

Whenever I include the Struts2 dependency, why do I have to do like this?

<dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>${struts.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>
    </dependency> 

If I don't do this, Eclipse Juno gives me error at this point.

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
 http://maven.apache.org/maven-v4_0_0.xsd

With this error:

Missing artifact com.sun:tools:jar:1.5.0

Is this the way to do it or is there a better way?

I noticed that this problem happens from version 2.1.6 and higher.

Upvotes: 0

Views: 2837

Answers (3)

Stephan
Stephan

Reputation: 43013

PROBLEM EXPLAINED

Actually, what happens is that struts2 relies on a system dependency, namely tools.jar. This dependency is found by resolving this path: ${java.home}/../lib/tools.jar.

If you compile your project with maven, maven will be clever enough to replace ${java.home} with the right JDK location.

For some reason, if you try to compile your mavenized project with eclipse (ie with m2e help generally), ${java.home} is resolved against the -vm eclipse command line parameter.


SOLUTION

If you want to solve this issue, DO NOT exclude the tools.jar. Instead force your eclipse to run with your favorite JDK in either of the following ways (since I don't know your OS, I'll give examples in an OS agnostic form):

  • Command line switch

/path/to/eclipse -vm /path/to/jdk/bin/javaw

Check this SO answer for an example on Windows.

  • eclipse.ini

-vm
/path/to/jdk/bin/javaw

Check this SO answer for an example on Windows.

Upvotes: 0

Dave Newton
Dave Newton

Reputation: 160181

You should not need to do this.

That you do indicates there's an issue in your Eclipse, Eclipse project, and/or Eclipse Maven plugin configuration. By way of comparison, I have S2 projects for essentially every version, and in no pom do I need to exclude the Java tools jar, and never have.

Upvotes: 0

ben75
ben75

Reputation: 28706

The artifact com.sun:tools:jar:1.5.0 is a jar from the JDK (not the JRE). This jar is not available in any maven repository but is located in <JDK_HOME>/lib. That's why you get this error.

When you specify an exclusion, maven won't try to find the jar (and so it won't fail).

Struts2 requires this dependency at compile time (not at runtime).

So setting an exclusion is the correct way of getting rid of this problem. Since maven need a JDK to run: the tools.jar will be available anyway when compiling the project.

Upvotes: 4

Related Questions