2012-07-29 62 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

相關問題