-2

I have runnable jar of a spring boot application. I have used it as a library in my java project. Now I want to hit the run method of this library, but I am getting an exception "java.lang.ClassNotFoundException: org.springframework.boot.web.support.SpringBootServletInitializer". How should I go about this?

Thanks in advance

Hi All, I have solved the issue on my own. The run/main method of the spring boot library will be called like CLassName.methodName(Parameters) i.e. after importing the class from the library.

Make a library using jfx plugin. Rather then using the eclipse IDE.

The error I was getting was because of the dependencies which were to be added in the build path of the project.

Do these things and one is good to go.

PS: Hope this helps anyone in future.

Ankit Pande
  • 7
  • 1
  • 5
  • 1
    Could you please state the exception? Even if it is not specific it will be more accurate than just verbal interpretation. What steps did you undertake. Please read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – fragmentedreality Jun 04 '19 at 10:23
  • Through the REST API. – Nikolas Charalambidis Jun 04 '19 at 10:23
  • NoClassDefFound!Its unable to load the configuration class when I call the main method from my code. – Ankit Pande Jun 04 '19 at 10:32
  • Maybe, instead of using the runnable jar as lib and calling the main method inside it, you could call using Process, like: Runtime.getRuntime().exec("java -jar your-runnalbe.jar"); from the rest api or anyway you want. – Brother Jun 04 '19 at 10:48
  • Can you show your main class, `pom.xml` and stacktrace with exceptions from console? – Valentyn Hruzytskyi Jun 04 '19 at 11:53
  • Caused by: java.lang.ClassNotFoundException: org.springframework.boot.web.support.SpringBootServletInitializer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 15 more – Ankit Pande Jun 04 '19 at 12:28
  • SpringBootServletInitializer is extended from the class that is being called... `public static void main (String[] args) throws Exception{ SpringBootWebApplication.main(args); System.out.println(args); }` – Ankit Pande Jun 04 '19 at 12:30
  • @ValentynHruzytskyi as the project is a java project it has no pom. I have imported a springboot project to this project as a runnable jar. – Ankit Pande Jun 04 '19 at 13:00
  • @AnkitPande If you don't have a `pom.xml`, how do you manage your dependencies? – g00glen00b Jun 06 '19 at 07:11
  • @ValentynHruzytskyi I have a pom.xml but it is for a spring boot project. Please read the question. I have two projects one has a pom and the second doesn't has a pom – Ankit Pande Jun 06 '19 at 08:46

1 Answers1

0

For a Spring Boot application, which needs to be used as a library, refer this link:

Creating a Multi Module Project

TechFree
  • 2,600
  • 1
  • 17
  • 18
  • I am not making a multi-module project to begin with. I want to use my spring boot application as a library in my java project. – Ankit Pande Jun 04 '19 at 13:31
  • @AnkitPande Why don't you move the shared stuff out into a pure library? – Mischa Jun 05 '19 at 05:47
  • Hi @Ankit, please refer to the link again, i think that is what you would want : How to create a multi-module project with Spring Boot, in which there is a library jar and a main application that uses the library. You could also use it just to see how to build a library on its own (i.e. a jar file that is not an application). – TechFree Jun 06 '19 at 06:18
  • 1
    @TechFree I have achieved this with mvn jfx plugin. Thanks. – Ankit Pande Jun 06 '19 at 08:48