【问题标题】:Adding classpath to jetty running in maven integration-test将类路径添加到在 Maven 集成测试中运行的码头
【发布时间】:2011-01-11 16:12:30
【问题描述】:

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

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

我在谷歌上搜索并找到了http://markmail.org/message/awtqrgxxttra3uxx,但据我所知,这实际上根本不起作用。未找到 .properties 文件。

【问题讨论】:

    标签: java maven-2 build-process jetty integration-testing


    【解决方案1】:

    您可以将您的附加配置文件放在/src/test/resources 下,并在插件配置中设置属性<useTestScope>true</useTestScope> 指定here

    使用TestScope

    如果为 true,则来自 testClassesDirectory 的类和范围“test”的依赖项首先放在类路径中。默认情况下这是错误的。

    【讨论】:

    • 哦,已经有一条带有相同链接的评论...我会留下答案 - 它更引人注目。
    • 对我不起作用。 Jetty 启动输出:[INFO] --- jetty-maven-plugin:9.3.7.v20160115:start (start-jetty) @ someapp --- [INFO] 为项目配置 Jetty:Verizon CHC Timer Server [INFO]未设置 webAppSourceDirectory。尝试 src/main/webapp [INFO] Reload Mechanic: automatic [INFO] Classes = /Users/mvmn/wrkdir/someapp/target/classes 2016-03-01 15:27:55.704:INFO::main: 日志记录已初始化 @4023ms [INFO] 上下文路径 = / [INFO] Tmp 目录 = /Users/mvmn/wrkdir/someapp/target/tmp [INFO] Web 默认值 = org/eclipse/jetty/webapp/webdefault.xml [INFO] Web 覆盖 = none 。 ..
    • 对我也不起作用。编辑:适用于版本 >= 7.0.0
    【解决方案2】:

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

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

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

    【讨论】:

    【解决方案3】:

    这应该可以使用webAppConfig 配置元素(下面的示例取自this thread):

    <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> 
    

    【讨论】:

    • 另一种可能更边缘化的方式是使用&lt;contextXml&gt;jetty-context.xml&lt;/contextXml&gt;,其中jetty-context.xml 配置&lt;Set name="extraClasspath&gt;../my/classes,../my/jars/special.jar&lt;/Set&gt;,参见Using the extraClasspath() method
    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多