disconf icon indicating copy to clipboard operation
disconf copied to clipboard

在使用disconf时 打包成jar后,找不到properties文件的问题怎么解决

Open chuanqi opened this issue 9 years ago • 10 comments

使用springboot最后打包为jar,在java -jar 运行时,提示找不到配置文件,配置的文件确定已经自动下载到了根目录下,请问这个问题怎么解决.??

chuanqi avatar Apr 21 '16 02:04 chuanqi

试了一下提供的demo也有同样的问题,

chuanqi avatar Apr 21 '16 03:04 chuanqi

提供具体错误信息

markyao avatar Apr 22 '16 09:04 markyao

你确定是执行 java -cp . -jar disconf-spring-boot-web-1.0.0.jar 吗

knightliao avatar Apr 23 '16 03:04 knightliao

跟 -cp没关系,应该是properties文件打包到Jar包中,代码resource.getFile()是无法访问Jar包内部的文件的,应该用resource.getInputStream(), 有没有哪个选项可以先解压缩再运行的?

eyakcn avatar Aug 31 '16 02:08 eyakcn

你看下 这里 https://github.com/knightliao/disconf-demos-java/tree/master/disconf-standalone-demo 之前有个版本已经fix这个问题了,启动Jar包时,它会将配置文件下载到jar包的外面。 我们公司也是按照这种方式 进行实践的

knightliao avatar Aug 31 '16 02:08 knightliao

启用下载的话确实没问题。不过如果不启用下载的话默认是要去classpath里找的,这个时候打包在jar包里的properties文件就无法被读取了。

eyakcn avatar Aug 31 '16 03:08 eyakcn

disconf.enable.remote.conf=false 如果你设置为false的话,disconf 程序还是可以正确读取配置的,前提是你的配置文件要在jar包外面存在。

knightliao avatar Aug 31 '16 03:08 knightliao

一般上,是不推荐把配置文件打进包里的。不过你说的确实是个问题,如果打包在jar里我尝试下是否有问题。

knightliao avatar Aug 31 '16 12:08 knightliao

好的:D

eyakcn avatar Sep 02 '16 07:09 eyakcn

Same issue.

An alternative temporary solution:

  1. In disconf.properties: a). set disconf.enable.remote.conf=false to disable remote download b). set disconf.enable_local_download_dir_in_class_path=false to disable read properties files in classpath c). notice the default disconf.user_define_download_dir=./disconf/download2
  2. Put your-custom.properties files in directory ${project.baseDir}/disconf/download2 which is defined in step 1.c
  3. Just restart to get working

coffee4code avatar Jun 23 '18 12:06 coffee4code