向maven exec添加一个jar:java classpath [英] add a jar to maven exec:java classpath

查看:145
本文介绍了向maven exec添加一个jar:java classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用maven运行java类的批处理文件,它取决于tools.jar(来自JDK)。

例如:

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

我的程序使用JDK中的tools.jar,我在maven中添加了一个指向它的系统依赖项。

因为exec:java目标没有不包括系统依赖项,我想手动从命令行添加依赖项。

虽然我预计它是微不足道的,但我可以找到实现它的方法。
任何帮助将不胜感激。

谢谢,

Avner

I have a batch file which runs a java class using maven which depends on tools.jar (from the JDK).
For example:
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=runtime
My program uses tools.jar from the JDK and I've added a system dependency in maven which points to it.
Since the exec:java goal doesn't include system dependencies, I want to add the dependency from the command line manually.
Although I expected it to be trivial I could find the way to do it. Any help will be appreciated.
Thanks,
Avner

推荐答案

我从 maven exec插件中读到的内容它允许您将可执行的依赖项配置为插件依赖项。

From what I read at maven exec plugin it allow you to configure you executable dependencies as plugin dependencies.

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

这篇关于向maven exec添加一个jar:java classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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