在我的java代码中,我想编译一个maven项目(mvn clean install
)。如何在不制作Runtime.getRuntime().exec()
的情况下完成这项工作?
答案 0 :(得分:3)
让我们看看......
$ which mvn
/usr/bin/mvn
$ cat `which mvn`
... lots of code ending with...
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
"-Dmaven.home=${M2_HOME}" \
${CLASSWORLDS_LAUNCHER} "$@"
$ cat `which mvn` | grep CLASSWORLDS
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
${CLASSWORLDS_LAUNCHER} "$@"
所以我相信你需要运行org.codehaus.plexus.classworlds.launcher.Launcher.main(new String[] {"clean", "install"})
。 YMMV。