2012-05-09 29 views
1

因为我试图在我的maven项目中设置一个嵌入容器,我希望它在集成测试阶段运行。我有两个码头问题,我无法解决:Jetty守护进程和useTestClasspath,我做错了什么?

  1. <daemon>true</daemon>没有预期的效果。服务器运行,但它然后锁定构建过程(实际上它阻止单元测试)。 那么我应该放置那个配置?
  2. <useTestClasspath>true</useTestClasspath>对我来说是一个谜。我不想使用src/main/webapp/WEB-INF/lib来放置postgresql jar(由jetty为数据源(postegresql-driver)调用),因为它将被嵌入到应用程序中,我不希望它在战争中(客户端)。所以我想使用<useTestClasspath>true</useTestClasspath>,但是当我把postgresql放在src/test/resources中时,它没有找到/识别它。 那么,我该如何使用该属性?

下面是完整的插件配置:

<plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>maven-jetty-plugin</artifactId> 
      <version>6.1.9</version> 
      <executions> 
       <execution> 
        <id>start-jetty</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>run-war</goal> 
        </goals> 
        <configuration> 
         <useTestClasspath>true</useTestClasspath> 
         <daemon>true</daemon> 
         <contextPath>agepro-prototype</contextPath> 
         <webApp> 
          ${project.build.directory}/agepro-prototype.war 
         </webApp> 
        </configuration> 
       </execution> 
       <execution> 
        <id>stop-jetty</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <connectors> 
        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
         <port>9091</port> 
        </connector> 
       </connectors> 
       <stopPort>9092</stopPort> 
       <stopKey>test</stopKey> 
      </configuration> 
     </plugin> 

在此先感谢您的帮助,你能提供给我。我必须为我的语法道歉,因为我的英语很不好。
问候,
Depado

回答

1

不知道关于你的第一个问题,但是对于你的第二个,指定你的主要依赖块PostgreSQL的罐子所规定的范围(这将阻止其在战争中被捆绑) ,并增加在码头插件定义一个额外的依赖块(与编译范围),这将使PostgreSQL的罐子可在码头运行:

<build> 
<plugins> 
    <plugin> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>maven-jetty-plugin</artifactId> 
     <version>6.1.9</version> 
     <executions> 
      <execution> 
       <id>start-jetty</id> 
       <phase>pre-integration-test</phase> 
       <goals> 
        <goal>run-war</goal> 
       </goals> 
       <configuration> 
        <daemon>true</daemon> 
        <contextPath>agepro-prototype</contextPath> 
        <webApp> 
         ${project.build.directory}/agepro-prototype.war 
        </webApp> 
       </configuration> 
      </execution> 
      <execution> 
       <id>stop-jetty</id> 
       <phase>post-integration-test</phase> 
       <goals> 
        <goal>stop</goal> 
       </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <connectors> 
       <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
        <port>9091</port> 
       </connector> 
      </connectors> 
      <stopPort>9092</stopPort> 
      <stopKey>test</stopKey> 
     </configuration> 
     <dependencies> 
      <dependency> 
       <groupId>postgresql</groupId> 
       <artifactId>postgresql</artifactId> 
       <version>9.1-901-1.jdbc4</version> 
      </dependency> 
     </dependencies> 
    </plugin> 
</plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.1-901-1.jdbc4</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

我不想使用src /主/ webapp/WEB-INF/lib放置postgresql jar(由jetty为数据源(postegresql-driver)调用),因为它会嵌入到应用程序中,我不希望它在战争中(客户端)。所以我想使用true,但是当我将postgresql放在src/test/resources中时,它找不到/识别它

不应该将jar放在任何文件夹中(src/main/resources或src/main/webapp/WEB-INF/classes),它们都应该被定义为你的pom中的依赖项。

我也想像useTestClasspath是当你定义Web应用程序的配置元素,因为它使用的包装战,其中将不包含您的测试资源/班

被忽略
+0

我唯一的问题是,PostgreSQL是在应用程序的服务器端使用,我想测试客户端。所以postgresql是在我的pom中声明的,但它在主要范围内而不在测试范围内。我正在尝试你在这里发送的代码。 它工作正常!非常感谢 !现在我试图运行码头容器,而不是阻塞生命周期的其余部分。 ' true'似乎不起作用。 – Depado

+0

http://docs.codehaus。org/display/MAVENUSER/Maven +和+ Integration + Testing - 我在你的pom中看到的一个区别是使用run-war目标,而不是上面文章中指定的运行目标 - 可以看出它为什么会产生差异,但可能值得一试? –

+0

已经尝试过。我尝试过运行,运行战争,部署战争(但因为我的jetty版本没有工作),而且它仍然阻止我的生命周期。硒插件和它的属性''工作正常......我不知道该怎么做。 – Depado

0

useTestClasspath/useTestScope仅适用于码头:运行

这就是为什么它不与码头工作:运行战争和其他码头:目标