11

我目前正在开发一个使用 Jersey 进行 REST 的网络应用程序。我使用 maven,stax-api-1.0.1 和 1.0.2 都被拉入我的 web-inf/lib。我认为stax api是JDK1.6的aprt?

为什么这些 JARS 包含在我的 Web 应用程序中?

这是我的 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>

4

2 回答 2

9

这个问题在问题的评论字段中得到了回答。向保罗·格莱姆致敬。

stax 确实包含在 Java 1.6 中,但 Maven 不知道您正在将应用程序部署到 Java 1.6 运行时。您的依赖项也不知道您使用的是什么运行时。事实上,它们可能是专门为 Java 1.5 甚至更早版本编写的。

是的,[使用 Maven 排除修复它] 将是 IMO 最简单的解决方案。下一步可能是为不同的目标运行时创建不同的配置文件。例如,“1.6”配置文件将排除 stax 等,但“1.5”配置文件会将它们留在其中。

于 2011-12-16T21:02:33.813 回答
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>
于 2012-02-07T01:09:49.680 回答