1

I am facing problem in running a spring boot jar file with external profile.

I have a spring boot project with jersey. I have placed the properties and some certificate file in different directories (for different servers development and production etc). The application needs these properties and certificate files.

My project structure looks like

MyProject
|_configurations
    |_local
    |_dev
|_web
    |__src
    |_target

I can run it locally on intelliJ by by setting the local profile in class path. I am generating the jar file out of the web directory.

When I run the jar file it complains and can not find the properties and certificate files.

These are my attempts

  1. Generate a new jar file by placing the required properties and certificates in resource directory under web\src\main directory.
  2. Putting the properties file in class path while running the jar file as

java –jar –DApp.config.file="c:\MyProject\conf\local" MyProject.jar

But nothing works and i get the same error, complaining that properties and certificate files could not be found.

Any help how this can be solved. Is there any other better solution to solve this kind of problem.

Tayab Hussain
  • 831
  • 9
  • 16
  • Generally you should put configuration and certifications stuffs within .src/main/resources folder because when is generated the jar all files in the folder will be added. – Jonathan JOhx Dec 27 '18 at 02:30
  • @JonathanJohx, this could be one solution, but what i want to achieve is to separate the configuration from the jar file. – Tayab Hussain Jan 07 '19 at 08:26

1 Answers1

0

Finally i figured out how we can work with the profiles.

  1. If the configuration files are inside the project Load the profile in class path by name of the profile while running the jar java -jar -Dspring.profiles.active=<Profile name> YourApp.jar

  2. the following If the configurations are outside the jar file Load the profile and configuration while running the jar

    java -jar -Dspring.profiles.active=<profile name> -Dloader.path=file:///C:/yourdirectorypath/MyApp/conf/environments/local MyApp.jar

Also note that the order should be same as in given command i.e. Profile > Dloader.path > jar file name

Tayab Hussain
  • 831
  • 9
  • 16