Maven plugin classloading

倾然丶 夕夏残阳落幕 提交于 2019-12-24 22:18:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!