我猜您想从maven命令运行您的应用程序。您可以使用exec插件,如下所示:
<build> <plugins> <plugin> <groupId>org.prehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1-beta-1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.package.MainClass</mainClass> <arguments> <argument>arg1</argument> <argument>arg2</argument> </arguments> </configuration> </plugin> </plugins></build>
您可能还需要在pom中使用它。
<repositories> <repository> <id>Maven Snapshots</id> <url>http://snapshots.maven.prehaus.org/maven2/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </repository></repositories><pluginRepositories> <pluginRepository> <id>Maven Snapshots</id> <url>http://snapshots.maven.prehaus.org/maven2/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository></pluginRepositories>
实际的配置可能会有所不同,具体取决于您最终使用的exec插件的版本-
我在某些版本上取得了成功,而在其他版本上却没有取得成功,因此找出正确版本的exec尝试是一次反复的尝试。您的项目的罐子。如果您有多个开发人员,这也很痛苦,因为一个开发人员的参数可能不适用于另一个开发人员,因此最好编写批处理/
shell脚本来启动应用程序。
为了完整起见,这里有一些示例代码,使可执行的jar文件与romaintaz答案中的链接一起使用。
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.package.MainClass</mainClass> </manifest> </archive> </configuration> </plugin> </plugins></build>



