views:

128

answers:

2

I'm trying to bind in a third party app to our project but have discovered that the unix paths of their property files have been hard-coded into several classes. It is probably possible to make minimal changes to their setup, so my question is: what are the possible (and quickest) ways to achieve this? The third party app uses neither ant nor spring, but just a build script that compiles the code into a .jar that is called from the command line.

+3  A: 

You could read the properties files as resources. Then you only have to put the directories containing these files into your classpath.

tangens
+1  A: 

You haven't actually said what you want to achieve. Would your application determine some paths and pass them to third party app via an API? Would something in your environment (for example a command line argument) specify the location of the files?

I would first refactor their code so that I know for certain that any hard coded strings are held in one defined place. So if for example they have

readProperties("/usr/thing/propertyFileXxx.txt");

or

static final String  PROPERTY_XXX = "/usr/thing/propertyFileXxx.txt";
readProperties(PROPERTY_XXX);

I would first consolidate to a single accessor for the properties

readProperties(PROPERTY_XXX_ENUM);

So now we have a well-defined single piece of code that determines where to obtain the properties of each type and a specific list of the types of properties.

Then we need some controllable way to define the set of property files to be used at run-time. I have used the idea suggested by @tangens of loading the properties as resourcees from a specific directory added to the classpath.

djna