2012-07-29 119 views
5

我有一个批处理文件,它使用依赖于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 = runtime
我的程序使用JDK中的tools.jar,并且在maven中添加了一个指向它的系统依赖项。
由于exec:java目标不包含系统依赖关系,我想从命令行手动添加依赖关系。
虽然我认为这是微不足道的,但我可以找到办法。 任何帮助将不胜感激。
谢谢,
阿夫纳添加一个jar到maven exec:java classpath

回答

10

从我在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> 
+0

这可以在命令行上完成吗?如果我只是为了添加依赖项而必须维护一个pom文件就太糟糕了。实际上,能够直接从命令行直接从jar中运行一个类并让maven负责提取依赖关系会非常有用。 – akostadinov 2013-09-04 05:22:28

相关问题