将Java spring-boot应用程序* .jar和其他文件部署到根目录中的heroku

我有一个名为qsysprereg2-1.0.jar的spring boot应用程序。我将已经编译过的jar文件+ Procfile +文件夹“ config”放入heroku git中,其中包含我的应用程序的文件为“ config / config.properties”。只是一些属性。 在Gradle中,我只有:

apply plugin: 'java'
task stage() {
    println("Go stage...")
}  

所有编译和部署成功。

结果我有错误:

java.io.FileNotFoundException: config/config.properties (No such file or directory)

当然是因为:

Running bash on ⬢ qprereg... up,run.9546 (Free)
~ $ ls
Procfile  qsysprereg2-1.0.jar  system.properties

哪里没有git的“ config”文件夹。但是“ config / config.properties”已被推送到git中。

如何在文件夹中添加文件以部署工件?

snowcarangid 回答:将Java spring-boot应用程序* .jar和其他文件部署到根目录中的heroku

对不起,但是我没有找到一个好的解决方案。我做了一些把戏。我将所有配置文件都放在jar中作为资源。在启动应用程序期间,我正在检查迪克罐子外部的文件,然后从资源处理到dist。新文件将毫无问题地保留在磁盘上。代码:

   public static void main(String[] args) {
        try {
            prepareConfig();
        } catch (IOException ex) {
            log.error("Config prepare fail.",ex);
            log.throwing(ex);
            throw new RuntimeException(ex);
        }
        SpringApplication.run(Application.class,args);
    }


    private static void prepareConfig() throws IOException {
        File dir = new File("config");
        if (!dir.exists() || !dir.isDirectory()) {
            log.info("Create config directory");
            Files.createDirectory(dir.toPath());
        }
        makeReady("config/config1.properties");
        makeReady("config/config2.properties");
        makeReady("config/config3.properties");
        makeReady("config/configN.properties");
    }

    private static void makeReady(String fileName) throws IOException {
        File file = new File(fileName);
        if (!file.exists()) {
            log.info("Create config file '{}'",file.getName());
            try (final InputStream stream = Application.class.getResourceAsStream("/" + fileName)) {
                Files.copy(stream,file.toPath());
            }
        }
    }
本文链接:https://www.f2er.com/3078475.html

大家都在问