0

I'm writing a converter which should convert file A to file B. Doing so, I'm using the config API from Apache Commons Configuration to filter those files so not every entry will be converted.

Now I made a jar file which has the config file inside it. Reading from this config file inside the jar is no problem but if I try to use the save() method I'll get a ConfigurationException: no file name has been set message.

If I try to set the file name programmatically the program throws a NullPointerException.

So my question is: can I modify an e.g. config.properties file inside my jar in a programatic way?

X-Fate
  • 323
  • 4
  • 13
  • Generally speaking, you can't and shouldn't. The config file is actually an entry within a zip file and updating zip files are just a pain in the code, as you need to extract all the files within it, expect the one you want to update, recreate the zip file and replace it with the old version, which can be further complicated by the JVM and it locking jar files – MadProgrammer Jan 20 '15 at 20:14
  • @MadProgrammer: That's a pitty. So you recommend to ... 1) extract the properties-file. 2) modify it 3) take the existing contents of the current jar file and write this + the modified config file to a new jar file? – X-Fate Jan 20 '15 at 20:27
  • 1
    No, I recommend that if you want to modify the configuration file, you store it externally, somewhere on the file system – MadProgrammer Jan 20 '15 at 20:32
  • How about putting config.properties outside the jar and access read/write to it relative to the jar's ./ root path via Java Properties.load() and .store()? – ecle Jan 20 '15 at 20:38
  • there is no `store()` method in `Apache Commons Configuration` ... at least not in the `FileConfiguration` interface I'm using. But I think there will be no other way than assume that my customer has a config file already that one could use. – X-Fate Jan 20 '15 at 20:42

0 Answers0