0

I have a spring boot app as qsysprereg2-1.0.jar. I pushed into heroku git already compiled jar file + Procfile + folder "config" with files for my app as "config/config.properties". Just some properties. In Gradle I have only:

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

All compiled and deployed successfully.

In result I have error:

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

Of course, because:

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

Where is no folder "config" from git. But "config/config.properties" had been pushed into git.

How to add the folder with files to deploy artifacts?

Evgeniy Egorov
  • 223
  • 2
  • 7
  • https://stackoverflow.com/questions/24724383/add-resources-config-files-to-your-jar-using-gradle – Ivan Lymar Nov 18 '19 at 19:43
  • maybe you can check the inside jar file that you created after build(artifact). whether the related file is there or not. If there is no file in your artifact, try to add the related resources to your classpath with your maven or gradle configs. – sopehl Nov 18 '19 at 19:52
  • no. forget about resources – Evgeniy Egorov Nov 19 '19 at 06:42

1 Answers1

0

Sorry, but I did not find a nice solution. I made some tricks. I put all my config files in jar as resources. During starting the app I am checking the files outside jar on dick then coping from resources to dist. New files are keeping on disk without problems. Code for that:

   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());
            }
        }
    }
Evgeniy Egorov
  • 223
  • 2
  • 7