javabasex

BaseX close Spring Boot classloader


I have a Spring Boot (2.7.5) with BaseX 10.3

On start up I have a server component starting the server in a @PostConstruct

System.setProperty("org.basex.path", basexDataPath);
Context c = new Context();
c.soptions.set(StaticOptions.DBPATH, basexDataPath);
this.server = new BaseXServer(c,sl.finish());

And a client component creating a session in also a @PostConstruct

ClientSession clientSession = new ClientSession(basexServerHost, basexServerPort, UserText.ADMIN, basexAdminPassword);

And then I load functx (still in postconstruct) :

RepoInstall ri = new RepoInstall(tmpLib.getAbsolutePath(),null);//tmpLib = functx file
clientSession.execute(ri);

In Eclipse it works but when packaged and running from the jar, the application fail to start because I get a ClassNotFoundException of my own class.

I figured out, that it can not find the class because the classloader is closed. And Basex is closing it :

Here is the stack :

closing stack trace

What is wrong with my implementation ? How can I avoid BaseX to close the classloader ?


Solution

  • The BaseX ModuleLoader used to close URLClassLoaders, assuming that it had instantiated them itself for module loading:

          if(loader instanceof URLClassLoader) {
          try {
            ((URLClassLoader) loader).close();
          } catch(final IOException ex) {
    

    But this could also affect the default classloader, in case it was an URLClassLoader, so it was fixed recently (b82b4c). The fix is not yet contained in a released version, though.