java 将类路径添加到在 maven 集成测试中运行的码头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2176067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding classpath to jetty running in maven integration-test
提问by Sindri Traustason
I'm trying to set up integration tests for a Maven project that produces a war file. (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.
我正在尝试为生成 war 文件的 Maven 项目设置集成测试。(如这里所见http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/。)但是我的War文件需要在类路径上有一堆 .properties 文件,我不想捆绑在War中。
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/awtqrgxxttra3uxxbut this, as far as I can tell, does not actually work at all. The .properties files are not found.
我在谷歌上搜索并找到了http://markmail.org/message/awtqrgxxttra3uxx,但据我所知,这实际上根本不起作用。未找到 .properties 文件。
回答by Pascal Thivent
This should be possible using the webAppConfigconfiguration 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>
回答by Gary Rowe
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 服务器可见,而不会潜入生产代码中。
回答by Innokenty
You can place your additional configuration files under /src/test/resourcesand set a property <useTestScope>true</useTestScope>in the plugin configuration as specified here:
您可以将其他配置文件放在插件配置下/src/test/resources并<useTestScope>true</useTestScope>在此处指定的插件配置中设置一个属性:
useTestScope
使用测试范围
If true, the classes from testClassesDirectory and dependencies of scope "test" are placed first on the classpath. By default this is false.
如果为 true,则 testClassesDirectory 中的类和范围“test”的依赖项首先放在类路径上。默认情况下这是错误的。

