使用exec插件执行应用程序时如何添加类路径条目 [英] How to add a classpath entry when executing the app with exec plugin

查看:89
本文介绍了使用exec插件执行应用程序时如何添加类路径条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

One of the components is looking for the persistence.xml using the java.class.path system property. It is desired to keep this file separately from jars in the /conf folder.

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

When running the app with exec:exec, classpath is formed from the path to the main jar plus path to every dependency. I can't seem to figure out how to add the /conf entry to the classpath.

我的命令行如下:

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

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

我尝试了参数"参数,但是如果我尝试将任何内容附加到%classpath上,执行都会失败. 我还尝试通过指定

I tried "arguments" parameter but the execution fails if I try to append anything to %classpath. I also tried to add a Class-Path entry to the manifest by specifying

<manifestEntries>
  <Class-Path>/conf</Class-Path>
</manifestEntries>

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

in the configuration for maven-jar-plugin, but the entry in the manifest has no effect on the value of java.class.path property.

推荐答案

您可以在POM文件的"build"部分中使用元素"resources".例如

You may use the element 'resources' in the 'build' section of your POM file. For example

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

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

This will copy the persistence.xml into the build output directory, i.e. it will place the persistence.xml on the classpath.

这篇关于使用exec插件执行应用程序时如何添加类路径条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆