Java Ka Baby Java Ka Baby - 1 year ago 87
Java Question

How to can I make maven build add resources to classpath?

I am building a jar using maven with simple maven install.
If I add a file to

src/main/resources
it can be found on the classpath but it has a config folder where I want that file to go but moving it inside the config folder makes it disappear from the classpath.

Answer Source

If you place anything in src/main/resources directory, then by default it will end up in your final *.jar. If you are referencing it from some other project and it cannot be found on a classpath, then you did one of those two mistakes:

  1. *.jar is not correctly loaded (maybe type-o in the path?)
  2. you are not addressing the resource correctly, for instance: /src/main/resources/conf/settings.properties is seen on classpath as classpath:conf/settings.properties
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download