0

My Spring boot app (v2.1.1.RELEASE) is packaged using below plugin and layout :

         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <finalName>my-service-${project.version}</finalName>
                        <mainClass>com.my.app.MainClass</mainClass>
                        <layout>ZIP</layout>
                    </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I am using below launch script :

java -Dloader.path=/path/to/config/dir/ -jar my-service-1.0.jar

In one of dependencies which my app has, below code is used to read the external xml config files (e.g. hbase-site.xml) :

URL url = ClassLoader.getSystemResource(filename);

which is why I am trying to make those files available using loader.path but the app still doesn't read the files present on the provided dir. Am I missing anything else?

Already referred : Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar?

Spring Boot Executable Jar with Classpath

tom
  • 719
  • 1
  • 11
  • 30
  • Have you checked if the directory structure is correct, based on this docs, https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html – Anil Feb 26 '19 at 04:05
  • Also try using @PropertySource("file:config.properties") – Anil Feb 26 '19 at 04:07
  • @Anil these files are xml config files required for dependencies. I need to pass this externally so that it can be made available by spring boot runtime. I updated the question also. So in this case "PropertySource" will not work as it expects the .properties file or something similar which has key-value pair in expected format. – tom Feb 26 '19 at 05:09

1 Answers1

1

I think it should be the problem of getSystemResource, try to use getClassLoader().getResourceAsStream(path)

yinhua
  • 337
  • 4
  • 18