使用Maven运行Java main的3种方式
maven使用exec插件运行java main方法,以下是3种不同的操作方式。
一、从命令行运行
1、运行前先编译代码,exec:java不会自动编译代码,你需要手动执行mvn compile来完成编译。
mvn compile
2、编译完成后,执行exec运行main方法。
不需要传递参数:
mvn exec:java -Dexec.mainClass="me.biezhi.App"
需要传递参数:
mvn exec:java -Dexec.mainClass="me.biezhi.App"
-Dexec.args="arg0 arg1 arg2"
指定对classpath的运行时依赖:
mvn exec:java -Dexec.mainClass="me.biezhi.App"
-Dexec.classpathScope=runtime