开发者

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?


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

hope it helps


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜