将类路径添加到在maven集成测试中运行的jetty

Sin*_*son 10 java integration-testing build-process maven-2 jetty

我正在尝试为生成war文件的Maven项目设置集成测试.(如此处所见http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/.)但是我的war文件需要在类路径上有一堆.properties文件,我不想捆绑在战争中.

有没有办法(最好是通过插件配置)将文件夹添加到jetty使用的类路径中?

我用Google搜索并发现了http://markmail.org/message/awtqrgxxttra3uxx但据我所知,这根本不起作用.找不到.properties文件.

Pas*_*ent 21

这应该可以使用webAppConfig配置元素(以下从该线程获取的示例):

<webAppConfig>
  <contextPath>/nportal</contextPath>
  <!-- All I want to do here is add in the /etc/jetty/classes for runtime files. For some reason I have to also add back in the /target/classes directory -->
  <extraClasspath>${basedir}/target/classes/;${basedir}/etc/jetty/classes/</extraClasspath>
</webAppConfig> 
Run Code Online (Sandbox Code Playgroud)


Gar*_*owe 16

如果您发现上述解决方案不适合您,请考虑将测试类路径包含在Jetty配置中.

<configuration>
   <useTestClasspath>true</useTestClasspath>
   ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后,这将允许您将所有方式的资源/类放在测试类路径上,并让它们对Jetty服务器可见,而不会让它们进入生产代码.

  • 如果版本7+用户来寻找答案,新的选项名​​称是`<useTestScope>`.更多信息,请访问http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Configuring_additional_parameters (13认同)

Inn*_*nty 5

您可以将其他配置文件放在插件配置中,并在此处指定/src/test/resources的属性<useTestScope>true</useTestScope>中设置属性:

useTestScope

如果为true,则testClassesDirectory中的类和作用域"test"的依赖项首先放在类路径上.默认情况下,这是错误的.