使用maven运行Java main的2种方式

一:直接在命令行运行

mvn clean compile exec:java -Dexec.mainClass="com.demo.App" -Dexec.args="aaa bbb"

二:使用插件运行

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>exec-maven-plugin</artifactId>
	<version>1.4.0</version>
	<executions>
		<execution>
			<phase>test</phase>
			<goals>
				<goal>java</goal>
			</goals>
			<configuration>
				<mainClass>com.demo.App</mainClass>
				<arguments>
					<argument>11111111</argument>
					<argument>22222222</argument>
				</arguments>
			</configuration>
		</execution>
	</executions>
</plugin>

配置好插件后,执行mvn test 即可执行main方法

你可能感兴趣的:(maven)