问题
Could anybody please explain how the Core Classloader loads resources when, for instance, surefire test plugin is used?
What I'd especially need to know is the order in which project sources and resources from target/classes + target/test-classes AND project dependencies are loaded.
For instance, if I have a resource which exists both in a project and in a dependency. Which one is loaded first?
Thank you
回答1:
It turned out the answer was really simple.
First off, one can see the plugin classpath in the debug mode, $mvn test -X
And the first entry is target/test-classes
, then target/classes
and then plugins and all the project dependencies.
回答2:
FYI: For example, jetty-plugin uses its own dependencies&classloader to configure Jetty. For example, in my case I wanted to override HashSessionMAnager (because of http://apache-wicket.1842946.n4.nabble.com/Session-optimization-td3321009.html). Running mvn jetty:run kept pushing in the standard HashSessionMAnager.
To override jetty-plugin's dependencies I had to make a jar out of my little overridden HashSessionMAnager and place a dependency block
<dependencies>
<dependency>
...
</dependency>
<dependencies>
inside jetty-plugin block. I guess it makes sense normally, when nothing is injected from the plugin to the real application, but might give you funky surprises.
来源:https://stackoverflow.com/questions/4443345/maven-plugin-classloading