Running Spring Boot with PropertiesLauncher not picking up external jars

Answered

I have a Spring Boot project, with the pom.xml configured to run with PropertiesLauncher so I can include externally built jars.

I have tried setting the loader.path as an environment variable LOADER_PATH, and as -Dloader.path=….
but the application is not picking up my external jars.

I can see -Dloader.path=… on the logged execution.

What do I need to do to allow IntelliJ to run Spring Boot appropriately?

0
3 comments

Please follow below and see if it works.

  1. Build an executable jar that uses PropertiesLauncher
  • In your pom.xml spring-boot-maven-plugin:
    • Set layout: ZIP or layout: JAR with mainClass=org.springframework.boot.loader.PropertiesLauncher (for Boot 2.x you can use layoutProperties).
    • Ensure the final jar contains org/springframework/boot/loader/PropertiesLauncher.
  1. Run the jar, not the main class, from IntelliJ
  • Create a Run/Debug Configuration of type Application (or JAR Application):
    • Main class: org.springframework.boot.loader.PropertiesLauncher
    • Use classpath of module: set to the module that contains your built jar only if you’re running from jar; otherwise prefer “JAR Application”.
    • Better: Use “Run/Debug Configuration | JAR Application”:
      • Path to JAR: <path-to-your-built-jar>.jar
      • Program arguments: your app args (if any)
      • VM options: -Dloader.path=/absolute/path/to/external-jars,/absolute/path/to/external-dir
      • Working directory: where relative loader.path would resolve from (recommend absolute paths)
      • Environment: LOADER_PATH can be set here instead of VM options if you prefer
0

Thanks, launching as JAR application worked.

Related - the classes I am instantiating that are being externally loaded are just being created with reflection (get the class name, instantiate an instance).

I would like to be able to make the class and associated code visible to the spring boot framework so I can use the spring boot annotations in the plugin. Is this possible?

0

Please try below options and see:

Component scan

  •  Ensure jar is on classpath (loader.path).
  •  @SpringBootApplication(scanBasePackages = {"app.pkg","plugin.pkg"}) or @ComponentScan("plugin.pkg").

Explicit import

  • Plugin exposes @Configuration.
  • Main app: @Import(PluginConfig.class) or an ImportSelector.

Auto-configuration (recommended for plugins)

  • Plugin jar has @Configuration + conditions.
  • Register:
  1.               Boot 3: META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration
  2.               Boot 2: META-INF/spring.factories (org.springframework.boot.autoconfigure.EnableAutoConfiguration=...)
0

Please sign in to leave a comment.