【问题标题】:How to add a classpath entry when executing the app with exec plugin使用 exec 插件执行应用程序时如何添加类路径条目
【发布时间】:2009-04-07 05:55:19
【问题描述】:

其中一个组件正在使用 java.class.path 系统属性查找 persistence.xml。希望将此文件与 /conf 文件夹中的 jar 分开保存。

当使用 exec:exec 运行应用程序时,类路径由主 jar 的路径加上每个依赖项的路径组成。我似乎无法弄清楚如何将 /conf 条目添加到类路径中。

我的命令行如下所示:

mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath com.testjar.App"

我尝试了“arguments”参数,但如果我尝试将任何内容附加到 %classpath,则执行失败。 我还尝试通过指定

将 Class-Path 条目添加到清单中
<manifestEntries>
  <Class-Path>/conf</Class-Path>
</manifestEntries>

在 maven-jar-plugin 的配置中,但是 manifest 中的条目对 java.class.path 属性的值没有影响。

【问题讨论】:

    标签: maven-2


    【解决方案1】:

    您可以在 POM 文件的“构建”部分中使用元素“资源”。例如

    <build>
     <resources>
      <resource>
       <directory>src/main/resources/config</directory>
       <includes>
        <include>persistence.xml</include>
       </includes>
       <targetPath>/</targetPath>
      </resource>
     </resources>
     ...
    </build>
    

    这会将persistence.xml复制到构建输出目录中,即将persistence.xml放在类路径中。

    【讨论】:

    • 差不多。但它必须是 &lt;targetPath&gt;&lt;/targetPath&gt; - 至少在 Windows 上,单个 / 会带来麻烦。
    • @Sergey,但您不希望文件在罐子里吗?
    • @Martin 你可以使用&lt;targetPath&gt;${project.build.directory}&lt;/targetPath&gt;
    • 是的,这不能回答问题。最终结果是生成的 jar 文件中没有资源。我也有这个问题。似乎是一个非常简单的请求,似乎没有令人满意的解决方案。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多