我正在尝试使用 spring-boot-cli 命令创建一个 Spring Boot 项目,我想从 Java 代码中执行这个命令。我目前使用的是3.0.6版本的spring-boot-cli,但是升级到这个版本后就报错了。谁能提出解决方案?
import org.springframework.boot.cli.compiler.autoconfigure.SpringBootCompilerAutoConfiguration;
import org.springframework.boot.cli.support.SpringBootCli;
import org.springframework.boot.cli.support.SpringCli;
import org.springframework.stereotype.Service;
import java.io.File;
@Service
public class ProjectGeneratorService {
public boolean generateProject(String packageName, String groupId, String artifactId, String version) {
String projectName = artifactId;
String basePackage = packageName;
File projectDir = new File(projectName);
SpringCli springCli = new SpringBootCli(new SpringBootCompilerAutoConfiguration());
String[] cliArgs = new String[]{
"init",
"--dependencies=web",
"--package-name=" + basePackage,
"--groupId=" + groupId,
"--artifactId=" + artifactId,
"--version=" + version,
projectDir.getAbsolutePath()
};
int exitCode = springCli.runAndHandleErrors(cliArgs);
return exitCode == 0;
}
}