12

I am currently developing a web app that uses Jersey for REST. I use maven, and both stax-api-1.0.1 and 1.0.2 are pulled into my web-inf/lib. I thought the stax api were a aprt of JDK1.6?

Why are those JARS included in my web application?

Here is my pom.xml

<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.glennbech</groupId>
    <artifactId>simplerest</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Simplerest Maven Webapp. Very simple REST.</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <!-- Jersey for REST -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.9</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.9</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.17</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>simplerest</finalName>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.25</version>
                <configuration>
                    <contextPath>/</contextPath>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>

</build>

Glenn Bech
  • 6,103
  • 4
  • 39
  • 56
  • Can you post your pom.xml? This depends (hur hur) on your dependencies. – Paul Grime Sep 10 '11 at 19:29
  • I posted my pom.xml, but my question is really why I would need the Stax-api jars in my web-inf lib. I thought stax was part of JDK1.6? – Glenn Bech Sep 10 '11 at 19:44
  • 2
    stax does come included in Java 1.6, but Maven does not know you are deploying your app to a Java 1.6 runtime. Nor do your dependencies know what runtime you are using. In fact, they may have been specifically written themselves to work with Java 1.5 or even earlier. – Paul Grime Sep 10 '11 at 19:48
  • I see. Thanks. So, I should probably try to fix this using maven exclusions? – Glenn Bech Sep 10 '11 at 19:50
  • 1
    Yeah, that would be the easiest solution IMO. A next step could be to create different profiles for different target runtimes. E.g. a "1.6" profile would exclude stax etc, but a "1.5" profile would leave them in. – Paul Grime Sep 10 '11 at 19:53
  • 1
    @Paul grime Would you mind removing the comment and provide an answer to this question? I'd be glad to accept it. – Glenn Bech Oct 05 '11 at 19:44

2 Answers2

10

This question was answered in the comment field of the question. Kudos to Paul Grime.

stax does come included in Java 1.6, but Maven does not know you are deploying your app to a Java 1.6 runtime. Nor do your dependencies know what runtime you are using. In fact, they may have been specifically written themselves to work with Java 1.5 or even earlier.

Yeah, [fixing it using maven exclusions] would be the easiest solution IMO. A next step could be to create different profiles for different target runtimes. E.g. a "1.6" profile would exclude stax etc, but a "1.5" profile would leave them in.

Community
  • 1
  • 1
Glenn Bech
  • 6,103
  • 4
  • 39
  • 56
5
<dependency>
  <groupId>the.thing.that</groupId>
  <artifactId>transitively-imports</artifactId>
  <version>the.stax.version</version>
  <exclusions>
    <!--  STAX comes with Java 1.6 -->
    <exclusion>
        <artifactId>stax-api</artifactId>
        <groupId>javax.xml.stream</groupId>
    </exclusion>
    <exclusion>
        <artifactId>stax-api</artifactId>
        <groupId>stax</groupId>
    </exclusion>
  </exclusions>
<dependency>
scot
  • 1,194
  • 14
  • 26