Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij spring boot PropertiesLauncher

I have spring boot application (1.3.5.RELEASE) which is packaged as a jar file and i would like to have the jdbc drivers in an external libs folder. So i am using the PropertiesLauncher which searches for external jar files.

It works fine when using java -jar -Dloader.path=lib/ but is does not work inside the Intellij IDE. Its a Maven project which is imported into Intellij.

Any hints for me?

like image 450
Guido Zockoll Avatar asked Oct 28 '25 07:10

Guido Zockoll


2 Answers

Following the answer of Andy I thought I will post how I did resolved it:

  1. I've added a profile for the dependency

    <profile>
        <id>intellij-properties-launcher</id>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-loader</artifactId>
                <version>2.0.6.RELEASE</version>
            </dependency>
        </dependencies>
    
    </profile>
    
  2. I activated the profile on Intellij on the maven tab

    Activation on IDE

  3. Changed the configuration according to andy Run Configuration

NOTE: Intellij Ultimate 2018.3. It will mark the Configuration as Invalid, but it works :)

I hope to help someone.

like image 103
Tama Avatar answered Oct 30 '25 23:10

Tama


When you use PropertiesLauncher it sets up a class loader with the contents of the configured loader.path and then uses this class loader to load and call your application's main class. When you launch your application's main class directly in your IDE, PropertiesLauncher isn't involved so the loader.path system property has no effect.

It is possible to use PropertiesLauncher in your IDE but it'll require a bit of extra configuration. You'll need to configure a run configuration that has spring-boot-loader and your application on the classpath that launches PropertiesLauncher. You can then use the loader.main system property to tell PropertiesLauncher the name of your application's main class.

like image 27
Andy Wilkinson Avatar answered Oct 30 '25 23:10

Andy Wilkinson