0

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.

Mawia
  • 4,220
  • 13
  • 40
  • 55
  • That is strange, I used Struts 2 on several project, I don't recall having to exclude this com.sun.tools JAR... What version of Struts2 are you using ? Are you using Maven in command line or as an Eclipse/Intellij plugin ? – Pierre Henry Mar 20 '13 at 10:04
  • @PierreHenry I am using maven plugin. Version below 2.1.6 does not give this error. – Mawia Mar 20 '13 at 10:17
  • If you build from command line (without the exclude), does it also give you this "Missing artifact" error ? – Pierre Henry Mar 20 '13 at 10:19
  • You can solve this issue without excluding anything: http://stackoverflow.com/a/19827445/363573 – Stephan Nov 07 '13 at 03:32

3 Answers3

4

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.

ben75
  • 29,217
  • 10
  • 88
  • 134
  • Setting an exclusion is NOT the correct way ! Check this answer instead: http://stackoverflow.com/a/19827445/363573 – Stephan Nov 07 '13 at 03:26
  • @Alex I disagree with the linked answer. It's about an eclipse specific problem. The question here is about maven. I my opinion you are missing the most important point : struts needs tools.jar ONLY at compile time ! – ben75 Nov 07 '13 at 09:26
  • @ben75 OP says that the error appears in **Eclipse Juno**. The linked answer gives at least an alternative way. – Stephan Nov 07 '13 at 09:47
0

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • So what sould OP do ? What should be done by debelopers for avoiding this problem ? – Stephan Nov 06 '13 at 12:32
  • @Alex OP should include more information so people can reproduce the error; I cannot. – Dave Newton Nov 06 '13 at 13:34
  • I recently had the same issue, here is how I solve it: http://stackoverflow.com/a/19827445/363573. You'll notice I did without excluding anything ;) – Stephan Nov 07 '13 at 03:30
0

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.

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329