質問
単にJavaクラスのmainメソッドを実行するためのMavenの「相」または「目標は」ありますか?私は単に「MVNの実行」のような何かを行うことによって、手動でテストしたいプロジェクトを持っています。
解決
execのMavenプラグインをrel="noreferrer"> href="http://www.mojohaus.org/exec-maven-plugin/"
プラグインの設定は、あなたのpom.xmlにある場合、呼び出しはmvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
mvn exec:java
ような単純なことができます。 Mojohaus上のプラグインサイトでは、より詳細なrel="noreferrer"> href="http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-plugin-dependencies.html" でます。<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.example.Main</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
他のヒント
1。編集のpom.xml
pom.xml
で次のプロパティを追加します。あなたはmain
メソッドが含まれている(すなわち、パッケージ名を含む)完全修飾クラス名を使用していることを確認します:
<properties>
<exec.mainClass>${fully-qualified-class-name}</exec.mainClass>
</properties>
2。ファイル名を指定して実行コマンド
さて端末から、次のコマンドをトリガします:
mvn clean compile exec:java
注あなたは-Dexec.args="xxx"
フラグを経て、さらに引数を渡すことができます。
のpom.xmlに新しいプラグインを追加する必要はありません。ただ、このコマンドを実行します。
mvn org.codehaus.mojo:exec-maven-plugin:1.5.0:java -Dexec.mainClass="com.example.Main" | grep -Ev '(^\[|Download\w+:)'
のためののMavenプラグインのexec を参照してください。より多くの利用状況ます。
clean package exec:java -P Class_Containing_Main_Method
コマンドを使用すると、次のMavenのセットアップで、プロジェクト内の唯一の主な方法(PSVM)を持っている場合もオプションです。
<properties></properties>
のpom.xml
セクションでクラスを言及するのを忘れないでください。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.main.class>com.test.service.MainTester</java.main.class>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>${java.main.class}</mainClass>
</configuration>
</plugin>
STS の実行構成に沿ってとMavenのセットアップ上記ます: