4

I have spring boot application packaged as executable jar. Application has one utility class with main method which I want to invoke through command line but it seems that command is unable to find the class in classpath.

Command:

java -cp client-stp-grid-publisher-SNAPSHOT.jar com.client.stp.util.JMXClientUtils

I tried to set jar classpath in MANIFEST.MF using gradle jar task but no help:

jar {
    baseName = 'client-stp-grid-publisher'
    manifest {
        attributes(
                'Class-Path': "BOOT-INF/classes/*"
        )
    }
}

Generated MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Class-path: BOOT-INF/classes/*
Start-Class: com.client.stp.ClientStpGridPublisherMain
Spring-Boot-Version: 1.5.10.RELEASE
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/

I understand that ideally executable jar can't be used as dependent library but is there any workaround to achieve my use case?

Other solution can be pass a flag to run main class or utility class as spring boot application but I don't want to run utility class as spring boot process.

Shashi Shankar
  • 859
  • 2
  • 8
  • 25

1 Answers1

6

may be you can test with command

java -cp client-stp-grid-publisher-SNAPSHOT.jar -Dloader.main=com.client.stp.util.JMXClientUtils org.springframework.boot.loader.PropertiesLauncher

It can be found in here.

mc1arke
  • 1,030
  • 10
  • 22
  • java -cp client-stp-grid-publisher-SNAPSHOT.jar -Dloader.main=com.client.stp.util.JMXClientUtils org.springframework.boot.loader.PropertiesLauncher – GiraffeTree Oct 25 '19 at 02:10