5

I have spring boot jar. It contains boot-inf folder with that folder it contains classes and lib folder. I need to run the certain class which is having main method. But I don't know how to run it. For normal jar we can use the below format to run the class from the jar.

java -cp "sample.jar;dependecy.jar" com.sample.ClassName

But in spring boot jar what is the format to run the class. Because it contains boot-inf folder. I am using gradle script to build the project

ArockiaRaj
  • 588
  • 4
  • 17
  • Not sure what you are trying to do. If you have jar, you can simply run from cmd as java -jar yourjar.jar – want2learn May 07 '18 at 15:48
  • I have a spring boot jar it. From the jar I need to execute the specific class which is having main method. In normal core java jar file i could easily execute the class using above format. But in spring boot jar I couldn't execute the class. I dont know the format to execute the class from spring boot jar – ArockiaRaj May 07 '18 at 16:05
  • you don't need to specify class with main method. Spring boot will take care of it for you. – want2learn May 07 '18 at 17:49
  • Have a look at https://stackoverflow.com/a/57960676/10318272 That helped me. – S. Doe Apr 21 '20 at 11:35

2 Answers2

4

It should be very easy, just:

java -jar sample.jar

where sample.jar is your spring boot jar.

See https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html

user2456718
  • 216
  • 1
  • 4
  • 1
    If your jar is a correctly packaged spring boot jar you should find inside the jar the `META-INF` directory and inside it the `MANIFEST.MF` file. In the file you should have two entries: `Start-Class`, that should be the class that you are trying to run, and `Main-Class`, with a class from Spring. The point is that if the jar is packaged correctly you don't have to specify the class from the command line beacause Spring boot will do that automatically for you. – user2456718 May 07 '18 at 16:10
0

You can try with the distribution to run the class in a jar. Build the project to create the dist. Then you can run the class as you mentioned in the question.

java -cp "sample.jar;dependecy.jar" com.sample.ClassName