Hi Guys !. I am building a Maven plugin to read the classpath from my webapp and then filter if the class is a controller or a service or something else. I could read the "/src/main/java" dir but I wasnt able to get a class intance from the .java files as I keep on getting "ClassNotFoundException". How could I bypass this and get this instance ?. Is there an object from the plugincontext that allows this ?.
For example: In my WebApp, I could have:
From my maven plugin, I would need to do something like:
To check if the class is a controller !. Obviously this is an example... I would be reading the classpath and the amount of controllers would not be always the same from project to project....
Hi Knute Storm. Thankx for your reply. No, I wouldnt be needing to access that dir. What I am needing is to create a "Class" instance of every RestController / Controller, so as to get or obtain metadata of it by reflection.
I could read the dir "src/main/java" but I am not able to create the class instances. Its like being and not being inside the context of my webapp.
I was able to load a class from my hosted application, but a simple one. Zero related dependencies. When I try to load a controller, it seems that it tries to load the associated dependencies and the loading fails.
Please cheack the attached picture...
Here it's me again... The thing I did to solve the issue was the following:
Considering the following image:
I made a code to load a controller class with all the related dependencies. To avoid the need of the user to provide parameters, I did the following:
1) Read the application POM file and get the 'dependencies' tag.
2) Get a reference to the Maven Local Repo and with all the related dependencies from the application (Point 1), I got a list (List<File>) of JARS needed to load the classes annotated with "Controller" or "RestController".
3) Create a "URLClassLoader" object which receives an array of type "URL" (which would I would be getting by applying the intermediate operation "map" and doing to every file ".toURL()").
4) Then, when loading a controller in the following way ("com.sports.soccer.PlayerController"), the loading won't fail as the JAR dependencies would be load also. In the URL array from point 3, it should be added a reference to the bytecode dir of the app.