openpojo icon indicating copy to clipboard operation
openpojo copied to clipboard

Classloader improvements for execution within IDE

Open myron0815 opened this issue 5 years ago • 4 comments

I got some different results/errors, when i run openpojo from Maven command line versus running inside Eclipse IDE. This comes from the fact, that when i execute the unit test with Eclipse internal "run as junit test", Eclipse computes the classpath from the projects output folder, and does not use the generated JAR artifact. This leads to problem, that "myproject.jar" is not loaded (since the JavaClassPathClassLoader does only load JAR files)

[main] INFO com.openpojo.reflection.java.packageloader.env.JavaClassPathClassLoader - Loading classes from: C:\Users\user\workspace\myproject\target\classes [main] WARN com.openpojo.reflection.java.packageloader.env.JavaClassPathClassLoader - Failed to load entries from: [C:\Users\user\workspace\myproject\target\classes]

But what about loading the classfiles from an exploded project folder? Like: https://github.com/myron0815/openpojo/commit/b986f73e6c37eeb50d6872970e597c13529e6288

myron0815 avatar Feb 12 '19 08:02 myron0815

Testing in maven happens pre-packaging, so no .jar would be created for testing, however if you add a .jar to your dependencies, you can run tests against the classes in it. Could you please give me an example of what you are seeing? This would be helpful to reproduce to see where the issue if coming from

oshoukry avatar Feb 13 '19 20:02 oshoukry

It's not a Maven problem, it's a different IDE approach, which would not see my dependency. "Problem" is the Eclipse IDE and it's Maven "workspace resolution" feature. Given a simple Maven project with 2 modules, one depends on other.

When run from command line, maven calculates the dependency hierarchy, and builds the dependency project first. The other module build now loads the JAR, everything works.

But when running the unit test within Eclipse (WITHOUT mvn test, just plain JUint), Eclipse sees the open dependant project, and adds it's output folder to classpath, not the built artifact. This IS the expected behaviour of an IDE, since you want your saved changes to take immediately effect (without the need for packaging). Eclipse (and basically any IDE) does not know anything about packaging. If i "close" the dependant module in Eclipse workspace, everything works as expected again...

This is why i modified your ClassLoader. I cannot change the classpath - this is set by "the runner" (be it Maven, or Eclipse junit run config) But when i see a folder ending with "classes" (*), then i try to load all the class files, as if they were inside JAR. This immediately worked inside IDE, seeing now my dependency class files :)

*) should be changed? needed at all? classes iss only maven style.... (bin for normal projects?) but didn't want to load all JRE classes...

myron0815 avatar Feb 14 '19 08:02 myron0815

Anything happening with this issue? I'm getting a lot of these logs when running tests through IntelliJ IDEA:

15:09:25.508 [Test worker] INFO com.openpojo.reflection.java.packageloader.env.JavaClassPathClassLoader - Loading classes from: C:\Program Files\Java\jdk-11.0.2\bin
15:09:25.510 [Test worker] WARN com.openpojo.reflection.java.packageloader.env.JavaClassPathClassLoader - Failed to load entries from: [C:\Program Files\Java\jdk-11.0.2\bin]

guaranadev avatar Nov 21 '19 14:11 guaranadev

I've the same issue. Any updates on it?

rusty85 avatar Mar 05 '21 08:03 rusty85