The other day Darren asked about how to access a properties file with some settings from within a Livecycle ES resp. ADEP DSC on the livecycle developers mailing list. I responded there, but I thought it’d be useful to post the solution here as well.
Essentially a Livecycle/ADEP DSC is nothing else but a .jar file that’s been crafted in a certain way. Darren wanted to have the .properties file within the DSC and needed to know how to access the file from Java code within the DSC. Here’s a working approach how this can be done:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | InputStream is = this .getClass().getClassLoader(). getResourceAsStream( "your_properties_file_here" ); Properties prop = new Properties(); if (is!= null ) { try { prop.load(is); return prop.getProperty( "someProperty" ); } catch ( ...probably IOException of some kind... ) { ... } } |
To refer to the actual file, starting from the jar’s root will work:
1 2 | getResourceAsStream("folder_with_the_propertyfile/ agentk.properties"); |
There you go, have fun writing DSCs with .properties files!
Comments on this entry are closed.