Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classloader improvements for execution within IDE #129

Open
myron0815 opened this issue Feb 12, 2019 · 4 comments
Open

Classloader improvements for execution within IDE #129

myron0815 opened this issue Feb 12, 2019 · 4 comments

Comments

@myron0815
Copy link

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: myron0815@b986f73

@oshoukry
Copy link
Member

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

@myron0815
Copy link
Author

myron0815 commented Feb 14, 2019

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...

@guaranadev
Copy link

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]

@rusty85
Copy link

rusty85 commented Mar 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants