[英]Deploy java spring-boot app *.jar to heroku with other files in root folder
我有一個 spring 啟動應用程序作為 qsysprereg2-1.0.jar。 我推入 heroku git 已經編譯 jar 文件 + Procfile + 文件夾“config”,我的應用程序文件為“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。
如何添加包含文件的文件夾以部署工件?
對不起,但我沒有找到一個好的解決方案。 我做了一些小把戲。 我將所有配置文件作為資源放在 jar 中。 在啟動應用程序期間,我正在檢查 dick 上 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());
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.