当前位置: 首页 > 知识库问答 >
问题:

将java spring-boot应用程序*.jar部署到heroku,并将其他文件放在根文件夹中

马绪
2023-03-14

我有一个Spring Boot应用程序qsysprereg2-1.0.jar。我将git已经编译好的jar文件+Procfile+文件夹“config”和应用程序的文件“config/config.properties”推入heroku。只是一些财产。我只有:

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。

如何添加包含文件的文件夹来部署工件?

共有1个答案

贝阳泽
2023-03-14

对不起,但我没有找到一个好的解决办法。我耍了些花招。我把我所有的配置文件放在jar中作为资源。在启动应用程序的过程中,我在dick上检查jar外的文件,然后从resources处理到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());
            }
        }
    }
 类似资料:
  • 问题内容: 我正在向其中部署文件,并希望将其他文件包括到该段中,如下所述: 使用Heroku CLI配置WAR部署 它成功部署了文件,但是在扩展应用程序的任何子文件夹中我都找不到文件。同时,存档中的所有其他文件都在其位置上,其他 文件也仅此而已。我试图添加一些具有相同结果的文件: 问题: heroku在哪里包括其他文件?如何前往那里? 这是heroku-cli的输出: 问题答案: 这些文件将被添加

  • 我想用SharingContent将声音从原始文件夹共享到另一个应用程序 我使用此代码共享文本和字符串

  • 我试图将Spring Boot应用程序部署到Heroku,但我无法做到这一点。我的应用程序会自动检测为"heroku-maven-plugin",但我想将其部署为Java应用程序。 我怎样才能做到这一点?

  • 我正在尝试在Heroku上部署一个可执行的Spring Bootjar。 我已经告诉Heroku从只包含以下文件的github存储库进行部署: 我的如下所示: 如果我查看github中的构建包项目,我可以看到有一个名为的脚本,它检查是否存在文件: https://github.com/heroku/heroku-buildpack-java/blob/master/bin/detect 我相信我的

  • 我有一个Windows文件夹结构和文件,如下所示 c:\源文件\file1.txt c:\源文件夹\subfolder1\file2.txt c:\源文件夹\子文件夹2\file3.txt 我想复制所有文件到目标文件夹,如下所示 c:\DestinationFile\file1.txt c:\DestinationFile\file2.txt c:\DestinationFile\file3.tx

  • 问题内容: 我正在尝试在Heroku上使用Flask开发我的第一个“大型”应用程序,并尝试将此处的基本教程与以下说明结合:https : //devcenter.heroku.com/articles/python与以下说明:http:// flask.pocoo.org/docs/patterns/packages/#larger- applications。它在本地与“先行启动”一起工作,但是