Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Checking configuration files inside jars

DZone's Guide to

Checking configuration files inside jars

· Java Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

Are you habit to have some configuration files packaged inside the jar of your application?

If so, you can still have a look at those configuration files in the running environment using the unzip Unix utility.

$ unzip -p /opt/myapp/lib/my-app.jar log4j.properties
log4j.rootLogger=INFO,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd-MMM hh:mm} [%-5p] %m%n

The -p option uncompress and prints the file content to standard output.

I like to include resource files in the deployable artifact, unless I want those files to be modifiable without repackaging. Hiding most of configuration helps to keep things simpler for the end user, but still those files can be accessed for the technical support.

By the way, the above log4j configuration is the one I used to replace some System.out/System.err in a simple command line based application. I was thinking to remove the date part ‘%d{dd-MMM hh:mm}’ and make it look like the output of ant/maven, but then I thought that -after all- the date is quite useful since the application in question is ran by cron redirecting the standard out into a file, so we keep that as a log of the last run, to have some clue in case of errors.

From http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/

Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}