java - How to add an external folder to the class path? -


so have following folder structure:

  • project
    • lib (running jar folder)
    • properties (property file load in folder)

i trying load property file via x.class.getclassloader().getresource("properties/filename"). method works in eclipse when build jar using maven fails find file, giving file not found exception.

i suspect folder not in classpath because if run getclassloader().getresources("") property folder never shows up. tried suggestions in previous questions on stackoverflow none have worked far.

i tried running java -cp , -classpath still failed.

when using maven, files *.properties , other not-compilable files must lie @ src/main/resources folder, default, available.

additionally, recommend use thread.currentthread().getcontextclassloader() proper classloader, in order load resources.

anyway, if want have custom folder @ classpath, suggest add resource, @ pom.xml, this:

<project>     ...     <build>         ...         <resources>             <resource>                 <!-- folder want resource (from project root folder), like: project/properties -->                 <directory>properties</directory>                 <!-- filtering if maven should post-process text files find , replace ${key} params: in cases, leave false -->                 <filtering>false</filtering>             </resource>         </resources>     </build> </project> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -