简体   繁体   English

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

[英]Adding classpath to jetty running in maven integration-test

I'm trying to set up integration tests for a Maven project that produces a war file. 我正在尝试为生成war文件的Maven项目设置集成测试。 (As seen here http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/ .) However I the war file requires a bunch of .properties files on the classpath, that I don't want to bundle in the war. (如此处所见http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/ 。)但是我的war文件需要在类路径上有一堆.properties文件,我不想捆绑在战争中。

Is there a way (preferably through plugin configuration) to add a folder to the classpath used by jetty? 有没有办法(最好是通过插件配置)将文件夹添加到jetty使用的类路径中?

I Googled this and found http://markmail.org/message/awtqrgxxttra3uxx but this, as far as I can tell, does not actually work at all. 我用Google搜索并发现了http://markmail.org/message/awtqrgxxttra3uxx但据我所知,这根本不起作用。 The .properties files are not found. 找不到.properties文件。

This should be possible using the webAppConfig configuration element (sample below taken from this thread ): 这应该可以使用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> 

If you find that the above solution doesn't work for you, consider including the test classpath into your Jetty configuration. 如果您发现上述解决方案不适合您,请考虑将测试类路径包含在Jetty配置中。

<configuration>
   <useTestClasspath>true</useTestClasspath>
   ...
</configuration>

This will then allow you to place all manner of resources/classes on the test classpath and have them visible to the Jetty server without them creeping into the production code. 然后,这将允许您将所有方式的资源/类放在测试类路径上,并让它们对Jetty服务器可见,而不会让它们进入生产代码。

You can place your additional configuration files under /src/test/resources and set a property <useTestScope>true</useTestScope> in the plugin configuration as specified here : 您可以将额外的配置文件下/src/test/resources和设置属性<useTestScope>true</useTestScope>为指定的插件配置在这里

useTestScope useTestScope

If true, the classes from testClassesDirectory and dependencies of scope "test" are placed first on the classpath. 如果为true,则testClassesDirectory中的类和作用域“test”的依赖项将首先放在类路径上。 By default this is false. 默认情况下,这是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM