我有一个批处理文件,它使用依赖于 tools.jar(来自 JDK)的 maven 运行 java 类。
例如:
mvn -f .\pom.xml -e exec:java -Dfile.encoding="UTF-8"-Dexec.mainClass=MyClass -Dexec.args="%1 %2 %3 %4 %5 %6 %7 % 8 %9"-Dexec.classpathScope=运行时
我的程序使用 JDK 中的 tools.jar,我在 maven 中添加了一个指向它的系统依赖。
由于 exec:java 目标不包含系统依赖项,因此我想从命令行手动添加依赖项。
尽管我预计这会很简单,但我可以找到实现它的方法。
任何帮助将不胜感激。
谢谢,
艾夫纳
最佳答案
根据我在 maven exec plugin 上阅读的内容它允许您将可执行依赖项配置为插件依赖项。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>com.example.myproject</groupId>
<artifactId>mylib</artifactId>
</executableDependency>
<mainClass>com.example.Main</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
关于java - 添加一个 jar 到 maven exec :java classpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11710485/