What classpath does maven set for different goals? Can you provide a link to official docs?

孤人 提交于 2019-12-25 07:39:17

问题


To what does Maven set the classpath for different goals?

My issue: I have a project that I am building in Jenkins. It gets checked out form SVN. As the next thing, a different file is checked out into workspace-root/mydir/my.properties

Then, maven test is run.

In the test, a class loads the file by searching it on the classpath. Why does that work? (I'm new to Jenkins and maven and am trying to figure out how the job I'm looking at works...)


回答1:


Maven uses the <dependencies/> defined in your project as puts them on the classpath of the plugins. Furthermore, in the <plugin/> section of each plugin, you can define additional <dependencies/> which are only to be used by the plugin (and will therefore not become part of the final artifact in any way, or visible on the mvn dependency:tree).

In regards to the tests, it's important to know that:

  • Resources under src/main/resources and src/test/resources are respectively copied to target/classes and target/test-classes. These two directories are added to your classpath. (The same is valid for src/main/java and src/test/java).

  • Each Maven plugin is executed in it's own classloader.

  • When executing tests, the maven-surefire-plugin will usually fork your tests into a separate classloader.

Check this link.




回答2:


a class loads the file by searching it on the classpath. Why does that work?

Because this is what maven is designed to do. It knows your dependencies, because you set them and makes assumptions about the structure of the modules you are building e.g. src/main/resources will be added and it add all these to the class path.



来源:https://stackoverflow.com/questions/24412796/what-classpath-does-maven-set-for-different-goals-can-you-provide-a-link-to-off

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