Christian
Christian

Reputation: 6430

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

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

Upvotes: 0

Views: 374

Answers (2)

carlspring
carlspring

Reputation: 32617

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.

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533530

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.

Upvotes: 0

Related Questions