Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to put configuration files in JARs?

We are having a debate at my office around what can and cannot go in a JAR file. It has been suggested that it is poor form to have anything that is not a .class file go into a JAR. We currently have some XML configurations for Ibatis/etc, some property files.. the usual. However, there is a push to extract all such files from JARs and put them onto the local file system of each deployment machine. Does this sound reasonable?

like image 546
Kallin Nagelberg Avatar asked Jan 31 '11 15:01

Kallin Nagelberg


People also ask

Can JAR files harm your computer?

It may crash if it does something it should not do, but it will be unable to do any damage.

Where should config files be?

System-wide software often uses configuration files stored in /etc , while user applications often use a "dotfile" – a file or directory in the home directory prefixed with a period, which in Unix hides the file or directory from casual listing. Some configuration files run a set of commands upon startup.


1 Answers

it is poor form to have anything that is not a .class file go into a JAR

That is nonsense. It is in fact very good form to put resources like icons and other data files that user used by the code into the JAR together with the code. This is what the getResource() and getResourceAsStream() methods of Class and ClassLoader are for, and it makes for much more robust applications than messing around with resource paths manually.

However, config files are possibly a different matter. If they're meant to be changed during or after deployment, then having them inside a JAR file is rather inconvenient, and having them in a separate directory is preferable.

like image 57
Michael Borgwardt Avatar answered Sep 20 '22 07:09

Michael Borgwardt