application.properties外面的jar文件怎么样 [英] application.properties outside jar file how to

查看:319
本文介绍了application.properties外面的jar文件怎么样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

spring中所述-boot-reference


在你的应用程序类路径上(例如你的jar里面),你可以拥有一个
的应用程序.properties为name提供合理的默认属性值
。在新环境中运行时,可以在jar之外提供覆盖名称的application.properties

On your application classpath (e.g. inside your jar) you can have an application.properties that provides a sensible default property value for name. When running in a new environment, an application.properties can be provided outside of your jar that overrides the name

I将重复的application.properties与覆盖的名称放在与jar文件相同的路径上,但是在运行应用程序时:

I place a duplicated application.properties with overridden name on the same path as jar file, however when running the application with:

java -jar target/myproject-0.0.1-SNAPSHOT.jar

名称值未被覆盖,它仍然是指的是jar文件里面的application.properties里面的一个。我也尝试过:

The name value is not overridden, it still refers to the one inside application.properties inside jar file. I also tried:

java -Dspring.config.location=/target/application.properties -jar target/myproject-0.0.1-SNAPSHOT.jar

但它不起作用,请帮忙。

But it does not work, please help.

编辑

当我将当前目录更改为 target 并运行它,它的工作原理。

When I change the current directory to target and run it, it works.

java -jar myproject-0.0.1-SNAPSHOT.jar

为什么?为什么不能在路径之外运行呢?

Why? Why cannot be outside the path and run it?

推荐答案

它不起作用,因为你试图从另一个启动jar文件夹:spring boot查找相对于当前文件夹的文件/文件夹。

It doesn't work because you are trying to launch the jar from another folder: spring boot looks for files/folder relative your current folder.

您可以:

1)复制 application.properties ./ ./ config / ,相对于当前文件夹。

1) copy application.properties either in ./ or ./config/, relative to your current folder.

2)或指定 -Dspring.config.location

$ java -Dspring.config.location=target/application.properties -jar target/myproject-0.0.1-SNAPSHOT.jar

这篇关于application.properties外面的jar文件怎么样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆