I am instructed to write a java tool that will run with the following command.
java -cp "jarName.jar" com.hw.Main --param=someParam
I have created the project with spring boot and can run the executable jar with
java -jar "jarName.jar"
But when I try the first command console thwors error
Error: Could not find or load main class com.hw.Main
No you can't because Spring Boot executable JARs have its own class loader so your Main class is not visible for the normal class loader.
Either you call it with
java -jar jarName.jar --param=someParam
or you need to call
java -cp jarName.jar org.springframework.boot.loader.JarLauncher --param=someParam
Becuase org.springframework.boot.loader.JarLauncher is the Spring Boot main class that launches Spring Boot.
But that's the same as java -jar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.