升级到版本 3.0.6 后从 Java 代码执行 Spring Boot CLI 命令时出错

问题描述 投票:0回答:0

我正在尝试使用 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;
    }
}
java spring spring-boot command-line-interface
© www.soinside.com 2019 - 2024. All rights reserved.