我想从 spring 作为服务在 java 进程(使用 ProcessBuilder 创建)中运行 pmd。
public class PMDService {
private ProcessBuilder processBuilder;
private void createProcess() {
processBuilder = new ProcessBuilder();
final Map<String, String> envMap = processBuilder.environment();
String path = envMap.get("Path");
path += "../../../../../../../static-code-analyzers/pmd/bin;";
envMap.put("Path", path);
}
public String getCommand(PMDParameters params) {
final StringJoiner command = new StringJoiner(" ");
command.add("cmd")
.add("/c")
.add("pmd")
.add("-d")
.add(params.getSourceCodePath())
.add("-f")
.add(params.getOutputFormat())
.add("-R")
.add(params.getResultSet())
.add(">")
.add(params.getResultsPath());
return command.toString();
}
public void runAnalyzer(PMDParameters params) throws IOException, InterruptedException {
createProcess();
processBuilder.command(getCommand(params));
final Process process = processBuilder.start();
process.waitFor();
}
当我使用邮递员测试其余端点时,出现以下错误:
""message": "无法运行程序 \"cmd /c pmd -d C:/bootcamp/Spring/springbootcode/springbootdemo -f xml -R rulesets/java/quickstart.xml > .\": CreateProcess error=2, The系统找不到指定的文件","
在postman中输入json
{
"sourceCodePath": "C:/bootcamp/Spring/springbootcode/springbootdemo",
"resultsPath": ".",
"outputFormat": "xml",
"resultSet": "rulesets/java/quickstart.xml"
}
蓝山帝景
相关分类