简体   繁体   中英

Building a jar and loading Properties/Config file from file system

I need to keep a property file in a filesystem and it must be included when I'm building my project. I have a ANT script to build it my program as .jar, but my jar file don't have any symptoms of referring to that config file when i use it in a app server.

This is my ANT script to include my properties file in classpath with dirset

<path id="project-classpath">
   <fileset dir="/var/edt/dependencies" includes="*.jar" />
   <dirset dir="/var/edt/config" />
   <pathelement path="/var/edt/config" />
</path>

PS. I'm trying to acheive this to keep my configuration files away from app server so any change in configuration will not impact on my program as well it will dynamically load my configurations and avoid a server restart.

Any help is appreciated.

Instead of...

<dirset dir="/var/edt/config" />
<pathelement path="/var/edt/config" />

...try...

<fileset dir="/var/edt/config" />

I learnt that we have quiet an options to do such things

  1. Putting our config files in a application server config directories where it can load dynamically, in my case its logback.xml and application server would be websphere..so I have put my config xml in Appserver/properties directories of websphere with scan property as true. Hope every app server has this way of loading config files at runtime.

  2. This is loading your configuration programmatically(my case would be using Joran configurator).

  3. And creating a jar with config file reference which I'm still trying to make it work.

Any other way to do this I'm willing to learn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM