2

这就是我所拥有的pom.xml

<dependency>
  <groupId>com.sun.jersey.jersey-test-framework</groupId>
  <artifactId>jersey-test-framework-grizzly</artifactId>
  <version>1.4</version>
  <scope>test</scope>
</dependency>

这是我之后看到的mvn --debug war:war

[...]
[DEBUG]    com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test
[DEBUG]       com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test
[DEBUG]          org.glassfish:javax.servlet:jar:3.0-b66:test
[DEBUG]       com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test
[DEBUG]          com.sun.grizzly:grizzly-http:jar:1.9.18-i:test
[DEBUG]             com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test
[DEBUG]             com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test
[DEBUG]             com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test
[DEBUG]          com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test
[DEBUG]             com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test
[DEBUG]          javax.servlet:servlet-api:jar:2.5:compile
[...]

注意最后一行。为什么不是"test",但是"compile"

附言。确实,这很奇怪。这是我的完整pom.xml(对不起,它不短):

[...]
<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.7</version> <!-- 10 Sep 2010 -->
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>xom</groupId>
    <artifactId>xom</artifactId>
    <version>1.2.5</version> <!-- 13 Oct 2010 -->
  </dependency>
  <dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.8.5</version> <!-- 9 Oct 2010 -->
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version> <!-- 9 Oct 2010 -->
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>1.6.2</version> <!-- 12 Oct 2010 -->
  </dependency>
  <dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>3.1</version> <!-- 2 Nov 2010 -->
  </dependency>
  <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>com.sun.jersey.jersey-test-framework</groupId>
    <artifactId>jersey-test-framework-grizzly</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>openejb-ejbd</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <!-- version see below in dependencyManagement section -->
  </dependency>
  <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version> <!-- 9 Oct 2010 -->
    <scope>provided</scope>
  </dependency>
</dependencies>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-core</artifactId>
      <version>${jersey.version}</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
      <version>${jersey.version}</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <version>${jersey.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey.jersey-test-framework</groupId>
      <artifactId>jersey-test-framework-grizzly</artifactId>
      <version>${jersey.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.openejb</groupId>
      <artifactId>openejb-ejbd</artifactId>
      <version>3.1.3</version> <!-- 26 October 2010 -->
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.4.2</version> <!-- 29 oct 2010 -->
    </dependency>
    <dependency>
      <groupId>hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
      <version>1.8.0.10</version> <!-- 12 October 2010 -->
      <scope>test</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
[...]

这是如何maven-war-plugin配置的:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.0</version>
  <configuration>
    <archive>
      <manifestEntries>
        <SCM-Revision>${buildNumber}</SCM-Revision>
      </manifestEntries>
    </archive>
  </configuration>
</plugin>
4

2 回答 2

1

这非常奇怪,运行时我没有得到相同的mvn输出--debug

$ mvn --debug 编译
...
[调试] com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test
[调试] com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test
[调试] com.sun.jersey:jersey-server:jar:1.4:test
[调试] com.sun.jersey:jersey-core:jar:1.4:test
[调试] asm:asm:jar:3.1:test
[调试] com.sun.jersey:jersey-client:jar:1.4:test
[调试] org.glassfish:javax.servlet:jar:3.0-b66:test
[调试] com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-http:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test
[调试] com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test
[调试] javax.servlet:servlet-api:jar:2.5:test
...

这与dependency:tree

$ mvn 依赖:树
[INFO] 正在扫描项目...
...
[信息] \- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test
[信息] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test
[信息] | +- com.sun.jersey:jersey-server:jar:1.4:test
[信息] | | +- com.sun.jersey:jersey-core:jar:1.4:test
[信息] | | \- asm:asm:jar:3.1:test
[信息] | +- com.sun.jersey:jersey-client:jar:1.4:test
[信息] | \- org.glassfish:javax.servlet:jar:3.0-b66:test
[信息] \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test
[信息] +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test
[信息] | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test
[信息] | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test
[信息] | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test
[信息] +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test
[信息] | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test
[信息] \- javax.servlet:servlet-api:jar:2.5:test
...

servlet-api工件具有test预期的范围。

您是否在某处servlet-api声明为具有范围的依赖项?compile这是我可以复制的唯一方法。


更新:mvn --debug我在粘贴您提供的所有依赖项后复制了输出。也就是说,我不知道如何解释maven-compiler-plugin执行时打印的这个输出。另请注意,它不同于dependency:tree

$ mvn 依赖:树
[INFO] 正在扫描项目...
...
[信息] --- maven-dependency-plugin:2.1:tree (default-cli) @ Q4098082 ---
[信息] com.stackoverflow:Q4098082:jar:1.0-SNAPSHOT
[信息] +- junit:junit:jar:4.7:test
[信息] +- xom:xom:jar:1.2.5:compile
[信息] | +- xml-apis:xml-apis:jar:1.3.03:compile
[信息] | +- xerces:xercesImpl:jar:2.8.0:compile
[信息] | \- xalan:xalan:jar:2.7.0:compile
[信息] +- org.mockito:mockito-all:jar:1.8.5:test
[信息] +- org.apache.commons:commons-io:jar:1.3.2:test
[信息] +- joda-time:joda-time:jar:1.6.2:compile
[信息] +- commons-httpclient:commons-httpclient:jar:3.1:compile
[信息] | +- commons-logging:commons-logging:jar:1.0.4:compile
[信息] | \- commons-codec:commons-codec:jar:1.2:compile
[信息] +- com.sun.jersey:jersey-server:jar:1.4:compile
[信息] | +- com.sun.jersey:jersey-core:jar:1.4:compile
[信息] | \- asm:asm:jar:3.1:编译
[信息] +- com.sun.jersey:jersey-client:jar:1.4:test
[信息] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test
[信息] | +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test
[信息] | | \- org.glassfish:javax.servlet:jar:3.0-b66:test
[信息] | \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test
[信息] | +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test
[信息] | | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test
[信息] | | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test
[信息] | | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test
[信息] | +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test
[信息] | | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test
[信息] | \- javax.servlet:servlet-api:jar:2.5:test
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.6-Final:compile
[信息] | +- org.hibernate:hibernate-core:jar:3.5.6-Final:compile
[信息] | | +- antlr:antlr:jar:2.7.6:compile
[信息] | | +- commons-collections:commons-collections:jar:3.1:compile
[信息] | | +- dom4j:dom4j:jar:1.6.1:编译
[信息] | | \- javax.transaction:jta:jar:1.1:compile
[信息] | +- org.hibernate:hibernate-annotations:jar:3.5.6-Final:compile
[信息] | | \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[信息] | +- cglib:cglib:jar:2.2:compile
[信息] | +- javassist:javassist:jar:3.9.0.GA:compile
[信息] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[信息] | \- org.slf4j:slf4j-api:jar:1.5.8:compile
[信息] +- org.apache.openejb:openejb-ejbd:jar:3.1.3:test
[信息] | +- org.apache.openejb:javaee-api:jar:5.0-3:test
[信息] | +- org.apache.openejb:openejb-core:jar:3.1.3:test
[信息] | | +- log4j:log4j:jar:1.2.12:test
[信息] | | +- org.apache.openejb:ejb31-api-experimental:jar:3.1.3:test
[信息] | | +- org.apache.openejb:openejb-api:jar:3.1.3:test
[信息] | | +- org.apache.openejb:openejb-javaagent:jar:3.1.3:test
[信息] | | +- org.apache.openejb:openejb-jee:jar:3.1.3:test
[信息] | | | +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:test
[信息] | | | | \- stax:stax-api:jar:1.0.1:test
[信息] | | | \- com.sun.xml.bind:jaxb-impl:jar:2.1.9:test
[信息] | | +- commons-cli:commons-cli:jar:1.1:test
[信息] | | +- org.apache.activemq:activemq-ra:jar:5.3.1:test
[信息] | | +- org.apache.activemq:activemq-core:jar:5.3.1:test
[信息] | | | +- commons-logging:commons-logging-api:jar:1.1:test
[信息] | | | +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:test
[信息] | | | +- org.apache.activemq:activeio-core:jar:3.1.2:test
[信息] | | | | \- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:test
[信息] | | | +- org.apache.activemq:kahadb:jar:5.3.1:test
[信息] | | | +- org.apache.activemq.protobuf:activemq-protobuf:jar:1.0:test
[信息] | | | +- org.apache.geronimo.specs:geronimo-j2ee-management_1.0_spec:jar:1.0:test
[信息] | | | \- commons-net:commons-net:jar:2.0:test
[信息] | | +- org.apache.openjpa:openjpa:jar:1.2.1:test
[信息] | | | +- net.sourceforge.serp:serp:jar:1.13.1:test
[信息] | | | +- commons-lang:commons-lang:jar:2.1:test
[信息] | | | \- commons-pool:commons-pool:jar:1.3:test
[信息] | | +- org.apache.geronimo.components:geronimo-connector:jar:2.1:test
[信息] | | +- org.apache.geronimo.components:geronimo-transaction:jar:2.1:test
[信息] | | +- org.objectweb.howl:howl:jar:1.0.1-1:test
[信息] | | +- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.2:test
[信息] | | +- org.apache.xbean:xbean-asm-shaded:jar:3.7:test
[信息] | | +- org.apache.xbean:xbean-finder-shaded:jar:3.7:test
[信息] | | +- org.apache.xbean:xbean-reflect:jar:3.7:test
[信息] | | +- org.apache.xbean:xbean-naming:jar:3.7:test
[信息] | | +- org.apache.openejb:commons-dbcp-all:jar:1.3-r699049:test
[信息] | | +- org.codehaus.swizzle:swizzle-stream:jar:1.0.1:test
[信息] | | +- wsdl4j:wsdl4j:jar:1.6.1:test
[信息] | | \- 石英:石英:罐子:1.5.2:测试
[信息] | +- org.apache.openejb:openejb-server:jar:3.1.3:test
[信息] | +- org.apache.openejb:openejb-loader:jar:3.1.3:test
[信息] | \- org.apache.openejb:openejb-client:jar:3.1.3:test
[信息] +- org.slf4j:slf4j-jdk14:jar:1.4.2:compile
[信息] +- hsqldb:hsqldb:jar:1.8.0.10:test
[信息] \- javax:javaee-api:jar:6.0:provided
...

以上是我分析依赖范围的参考,看起来是对的。我不知道为什么maven-compiler-plugin在调试模式下输出结果不同,我不知道这是否是预期的,我从不关注输出。

附加说明,在执行javax.servlet:servlet-api:jar:2.5期间位于(巨大的)测试类路径上compiler:testCompile

因此,虽然我没有完整的解释,但我无法发现任何副作用。

于 2010-11-04T16:09:06.590 回答
0

这是我为解决问题所做的:

[...]
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.0</version>
  <scope>provided</scope>
  <exclusions>
    <exclusion>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
    </exclusion>
  </exclusions>
</dependency>
[...]
于 2010-11-21T07:25:33.777 回答