lundi 7 juin 2021

Classloader does not look 'outside' maven dependencies

In a maven module with no dependencies to maven module X I am trying to load a class from module X. Is this possible? I cant add a dependency (cycle) and reflection is necessary in my case.

With FilesUtils I can find de files, no issues here. However then I try to run some tests to find out if I can load a class<?> with a path but no results so far.

Both Classloader and URLClassloader get instansiated within my maven module and the following did not work.

urls = new URL[]{
                new File("biz-test/target/classes").toURI().toURL(),
                new File("biz/target/test-classes").toURI().toURL(),
            };
Classloader cl = new URLClassloader(urls);

Also tried Class.forName in multiple ways (complete path, replacing linux / with ., class only, package path only)

I read about google reflections library, but this is a very large library? Any disadvantages to this?

My last option will be to move this generator to a module that can acces all the necessary dependencies.





Aucun commentaire:

Enregistrer un commentaire