[英]Maven can't find org.codehaus.mojo:exec-maven-plugin at command line
[英]exec-maven-plugin could not find or load main class but output runs fine on the command line
我嘗試使用exec-maven-plugin運行Java程序。
我使用以下pom代碼段:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dmyproperty=myvalue</argument>
<argument>-cp</argument>
<argument>"/home/vogella/libs/*"</argument>
<argument>com.vogella.test.Main</argument>
</arguments>
</configuration>
</plugin>
com.vogella.test.Main
類包含在/ home / vogella / libs / *中的一個jar文件中。 如果我運行mvn -X clean install exec:exec
命令, mvn -X clean install exec:exec
看到以下錯誤消息:
[DEBUG]執行命令行:java -Dmyproperty = myvalue -cp“ / home / vogella / libs / *” com.vogella.test.Main錯誤:找不到或加載主類com.vogella.test.Main
如果我在啟動Maven構建的shell中復制命令行( java -Dmyproperty=myvalue -cp "/home/vogella/libs/*" com.vogella.test.Main
),則Java程序將正確執行。
知道我的Maven安裝有什么問題嗎?
使用CLI,bash擴展了/ home / vogella / libs / *表達式,並解析為文件列表。 使用Maven,可以直接執行表達式,而不進行擴展。 因此它仍然是“ / home / vogella / libs / *”,這不是有效的jar文件。 通過使用antrun插件並在腳本中使用java Ant任務,您可能會獲得更大的成功。 螞蟻比其他任何人都更了解通配符。
您需要通過依賴項設置類路徑。 使用命令行參數-cp可以顯式設置類路徑,但這不適用於maven cp。 這是通過依賴關系構造的。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
<arguments>
<argument>${project.basedir}/src/my/mavenized/GenerateHeroLanguage.mwe2</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xtext</artifactId>
<version>2.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase</artifactId>
<version>2.5.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
如先前的回答所述,Maven不能很好地處理通配符。 您應該遵循“行家方式”並一一傳遞它們,也可以嘗試使用“ commandlineArgs ”。
我不確定這是否行得通,但是也許您可以使用以下方法再次嘗試:
<commandlineArgs>
代替。 我碰到了與此相關的JIRA問題,聽起來像您所需要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.