1

I have a situation a work where we have several jar filed in npm packages. If I add all the paths to the classpath before running my spring mvc app, it works fine.

But we want a "modular" way of doing this. IE, I don't know of all the packages that may or may not be there at runtime. I have a base folder, and I can easaly do a recusive file scan for all jar files, but how do I then load them before the component scan so everything is wired in correctly? I have this standard in my base Application class:

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
}

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
}

I assume I have to do something in my main() before I call run(), but im not sure what to do.

EDIT I have been trying to get this to work, and forgot to mention that this is a .war file in a tomcat container, and I don't think the main() method is being called.

mmaceachran
  • 3,178
  • 7
  • 53
  • 102
  • Perhaps this: https://www.baeldung.com/java-classloaders – Randy Casburn Dec 05 '18 at 16:00
  • Have a look at this answer https://stackoverflow.com/questions/11016092/how-to-load-classes-at-runtime-from-a-folder-or-jar . You can repeat same approach for each jar you want to load early in tour `main` – David Soroko Dec 05 '18 at 16:02

0 Answers0