mardi 12 novembre 2019

Loading a class from Maven dependency to my ClassLoader

I have a simple Java proyect where I want load a class from one of my Maven dependencies. I am using this code:

ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader currentClassClassLoader = TestGeneratorApplication.class.getClassLoader();
ClassLoader sysClassloader = ClassLoader.getSystemClassLoader();

String className = "My Class qualified name from my maven dependency";

Class<?> targetClass    = ReflectionUtils.forName(className, currentThreadClassLoader);
Class<?> targetClass2   = ReflectionUtils.forName(className, currentClassClassLoader);
Class<?> targetClass3   = ReflectionUtils.forName(className, sysClassloader);

The three ClassLoaders where I am searching gives me the same message (Could not get type for name ... ClassNotFoundException)

I don't know where search this class when I executed my method.

My maven dependency is a war defined like a normal in the pom:

<dependency>
    <groupId>mygroupid</groupId>
    <artifactId>myartefactid</artifactId>
    <version>4.2.0-2</version>
    <type>war</type>
</dependency>

Thanks in advance





Aucun commentaire:

Enregistrer un commentaire