这就是我在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"
?
PS。确实很奇怪。这是我的完整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>
答案 0 :(得分:1)
这非常奇怪,在使用mvn
运行--debug
时,我得不到相同的输出:
$ mvn --debug compile ... [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] com.sun.jersey:jersey-server:jar:1.4:test [DEBUG] com.sun.jersey:jersey-core:jar:1.4:test [DEBUG] asm:asm:jar:3.1:test [DEBUG] com.sun.jersey:jersey-client: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:test ...
与dependency:tree
:
$ mvn dependency:tree [INFO] Scanning for projects... ... [INFO] \- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test [INFO] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test [INFO] | +- com.sun.jersey:jersey-server:jar:1.4:test [INFO] | | +- com.sun.jersey:jersey-core:jar:1.4:test [INFO] | | \- asm:asm:jar:3.1:test [INFO] | +- com.sun.jersey:jersey-client:jar:1.4:test [INFO] | \- org.glassfish:javax.servlet:jar:3.0-b66:test [INFO] \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test [INFO] +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test [INFO] | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test [INFO] | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test [INFO] | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test [INFO] +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test [INFO] | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test [INFO] \- javax.servlet:servlet-api:jar:2.5:test ...
servlet-api
工件的范围符合test
。
您是否将servlet-api
声明为依赖compile
范围?这是我能够重现的唯一方式。
更新:在粘贴您提供的所有依赖项后,我使用mvn --debug
复制了输出。也就是说,我不知道如何解释执行maven-compiler-plugin
时打印的输出。另请注意,它与dependency:tree
:
$ mvn dependency:tree [INFO] Scanning for projects... ... [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ Q4098082 --- [INFO] com.stackoverflow:Q4098082:jar:1.0-SNAPSHOT [INFO] +- junit:junit:jar:4.7:test [INFO] +- xom:xom:jar:1.2.5:compile [INFO] | +- xml-apis:xml-apis:jar:1.3.03:compile [INFO] | +- xerces:xercesImpl:jar:2.8.0:compile [INFO] | \- xalan:xalan:jar:2.7.0:compile [INFO] +- org.mockito:mockito-all:jar:1.8.5:test [INFO] +- org.apache.commons:commons-io:jar:1.3.2:test [INFO] +- joda-time:joda-time:jar:1.6.2:compile [INFO] +- commons-httpclient:commons-httpclient:jar:3.1:compile [INFO] | +- commons-logging:commons-logging:jar:1.0.4:compile [INFO] | \- commons-codec:commons-codec:jar:1.2:compile [INFO] +- com.sun.jersey:jersey-server:jar:1.4:compile [INFO] | +- com.sun.jersey:jersey-core:jar:1.4:compile [INFO] | \- asm:asm:jar:3.1:compile [INFO] +- com.sun.jersey:jersey-client:jar:1.4:test [INFO] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test [INFO] | +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test [INFO] | | \- org.glassfish:javax.servlet:jar:3.0-b66:test [INFO] | \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test [INFO] | +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test [INFO] | | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test [INFO] | | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test [INFO] | | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test [INFO] | +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test [INFO] | | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test [INFO] | \- javax.servlet:servlet-api:jar:2.5:test [INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.6-Final:compile [INFO] | +- org.hibernate:hibernate-core:jar:3.5.6-Final:compile [INFO] | | +- antlr:antlr:jar:2.7.6:compile [INFO] | | +- commons-collections:commons-collections:jar:3.1:compile [INFO] | | +- dom4j:dom4j:jar:1.6.1:compile [INFO] | | \- javax.transaction:jta:jar:1.1:compile [INFO] | +- org.hibernate:hibernate-annotations:jar:3.5.6-Final:compile [INFO] | | \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile [INFO] | +- cglib:cglib:jar:2.2:compile [INFO] | +- javassist:javassist:jar:3.9.0.GA:compile [INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile [INFO] | \- org.slf4j:slf4j-api:jar:1.5.8:compile [INFO] +- org.apache.openejb:openejb-ejbd:jar:3.1.3:test [INFO] | +- org.apache.openejb:javaee-api:jar:5.0-3:test [INFO] | +- org.apache.openejb:openejb-core:jar:3.1.3:test [INFO] | | +- log4j:log4j:jar:1.2.12:test [INFO] | | +- org.apache.openejb:ejb31-api-experimental:jar:3.1.3:test [INFO] | | +- org.apache.openejb:openejb-api:jar:3.1.3:test [INFO] | | +- org.apache.openejb:openejb-javaagent:jar:3.1.3:test [INFO] | | +- org.apache.openejb:openejb-jee:jar:3.1.3:test [INFO] | | | +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:test [INFO] | | | | \- stax:stax-api:jar:1.0.1:test [INFO] | | | \- com.sun.xml.bind:jaxb-impl:jar:2.1.9:test [INFO] | | +- commons-cli:commons-cli:jar:1.1:test [INFO] | | +- org.apache.activemq:activemq-ra:jar:5.3.1:test [INFO] | | +- org.apache.activemq:activemq-core:jar:5.3.1:test [INFO] | | | +- commons-logging:commons-logging-api:jar:1.1:test [INFO] | | | +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:test [INFO] | | | +- org.apache.activemq:activeio-core:jar:3.1.2:test [INFO] | | | | \- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:test [INFO] | | | +- org.apache.activemq:kahadb:jar:5.3.1:test [INFO] | | | +- org.apache.activemq.protobuf:activemq-protobuf:jar:1.0:test [INFO] | | | +- org.apache.geronimo.specs:geronimo-j2ee-management_1.0_spec:jar:1.0:test [INFO] | | | \- commons-net:commons-net:jar:2.0:test [INFO] | | +- org.apache.openjpa:openjpa:jar:1.2.1:test [INFO] | | | +- net.sourceforge.serp:serp:jar:1.13.1:test [INFO] | | | +- commons-lang:commons-lang:jar:2.1:test [INFO] | | | \- commons-pool:commons-pool:jar:1.3:test [INFO] | | +- org.apache.geronimo.components:geronimo-connector:jar:2.1:test [INFO] | | +- org.apache.geronimo.components:geronimo-transaction:jar:2.1:test [INFO] | | +- org.objectweb.howl:howl:jar:1.0.1-1:test [INFO] | | +- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.2:test [INFO] | | +- org.apache.xbean:xbean-asm-shaded:jar:3.7:test [INFO] | | +- org.apache.xbean:xbean-finder-shaded:jar:3.7:test [INFO] | | +- org.apache.xbean:xbean-reflect:jar:3.7:test [INFO] | | +- org.apache.xbean:xbean-naming:jar:3.7:test [INFO] | | +- org.apache.openejb:commons-dbcp-all:jar:1.3-r699049:test [INFO] | | +- org.codehaus.swizzle:swizzle-stream:jar:1.0.1:test [INFO] | | +- wsdl4j:wsdl4j:jar:1.6.1:test [INFO] | | \- quartz:quartz:jar:1.5.2:test [INFO] | +- org.apache.openejb:openejb-server:jar:3.1.3:test [INFO] | +- org.apache.openejb:openejb-loader:jar:3.1.3:test [INFO] | \- org.apache.openejb:openejb-client:jar:3.1.3:test [INFO] +- org.slf4j:slf4j-jdk14:jar:1.4.2:compile [INFO] +- hsqldb:hsqldb:jar:1.8.0.10:test [INFO] \- javax:javaee-api:jar:6.0:provided ...
以上是我对分析依赖关系范围的参考,看起来是正确的。我不知道为什么maven-compiler-plugin
在调试模式下输出不同的结果,我不知道这是否是预期的,我从不关注输出。
补充说明,javax.servlet:servlet-api:jar:2.5
在compiler:testCompile
执行期间位于(巨大的)测试类路径上。
因此,虽然我没有完整的解释,但我无法发现任何副作用。
答案 1 :(得分: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>
[...]