依赖hutool工具类
// 定义要执行的shell命令
String command = StrUtil.format("source /etc/profile;source ~/.bash_profile;cd {};$MAVEN_HOME/bin/mvn --settings $MAVEN_HOME/conf/settings.xml archetype:generate -B " +
" -DarchetypeGroupId={}" +
" -DarchetypeArtifactId={}" +
" -DarchetypeVersion={}" +
" -DgroupId={}" +
" -DartifactId={}" +
" -Dversion={} &>{}",
codeDest,
archetype.getArchetypeGroupId(),
archetype.getArchetypeArtifactId(),
archetype.getArchetypeVersion(),
archetype.getGroupId(),
archetype.getArtifactId(),
archetype.getVersion(),
logLocation);
// 拼接命令行数组,这个是必须的,因为要用到shell 的特性
String[] cmd = {
"/bin/bash", "-c",
command
};
// 执行命令
Process process = RuntimeUtil.exec(cmd);
// 等待命令执行完毕
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new BusinessException("调用本地系统命令异常,命令如下:" + command + ",结果异常,详情见日志文件" + logLocation);
}
// 获取命令返回结果
String result = RuntimeUtil.getResult(process);
标签:系统命令,process,命令,command,执行,archetype,String
From: https://www.cnblogs.com/PythonOrg/p/18135956