hylton
hylton

Reputation: 61

Add classpath to folder containing property files in Maven

I have a property file which is not located in a classpath in Maven.

Therefore I can't reach it with:

ClassLoader.getSystemClassLoader().getResourceAsStream(PROPS_FILE);

How can I add the folder containing the property file to the classpath, so it will be available during build and test of the project?

Upvotes: 6

Views: 13792

Answers (4)

Brian
Brian

Reputation: 6450

If you really don't like Maven's enforcement of certain directories, use the build-helper plugin to add your own directory to the classpath as generated by "mvn eclipse:eclipse".

Upvotes: 0

khmarbaise
khmarbaise

Reputation: 97399

The best is to put that file under correct location in Maven like either src/main/resources and/or src/test/resources depending where it will be needed.

Upvotes: 1

byteslash
byteslash

Reputation: 41

Just add the file into the resources folder under src/main maven project. i did that and works like a charm.

hope it helps

Upvotes: 4

dhable
dhable

Reputation: 2879

Under the task you can add a set of resources and testResources like so:

  <resources>
    <resource>
      <directory>somedir</directory>
    </resource>
  </resources>

  <testResources>
    <testResource>
      <directory>test/unit</directory>
    </testResource>
  </testResources>

They also allow you to define exclusion and inclusion rules. This is very powerful for a legacy code base but for new code bases, you should follow the maven's standard directory layout to avoid lots of custom definitions in your POM files.

Upvotes: 3

Related Questions