aspose file tools
The moose likes Java in General and the fly likes Java property files best practices Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java property files best practices" Watch "Java property files best practices" New topic
Author

Java property files best practices

ParagS Kulkarni
Ranch Hand

Joined: Oct 04, 2004
Posts: 60
I have to read the property file. Could suggest me the best way to handle the property file.
My code is deployed on the server as a jar file.
I have to totally avoid the hardcoding.

Currently I am reading the properties using.

Properties prop = readProperties("C:\\PPMCustomCode\\DemandService.properties");
String endpoint = (String)prop.getProperty("ENDPOINT_URL");

It is not convincing & not a best way.
I tried using the resource bundle also still some hard coding remains. Can I keep my properties file in the same folder as the jar file & it will take the relative path? In RAD we could configure it in the admin console. I don’t have that liberty to use server configuration settings here, as I am working on JBoss.

Thanks, Parag
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 377
Ok here is how i am reading the property file in IBM websphere Appliation server

I have Set the System propery in the jvm command line option in websphere whose value is the path to property file

Then inside the code read the System property then use it read the property.

e.g.

system.properties
log_file_property_path=c:\app\log4j.properties
app_secific_property_path=c:\app\app.properties

then set the System property using -Dfile_paths="path to system.properties"

then in the code

String s=System.getProperty(file_paths);

Property p=new Property(s);

FYI

how to set system property in JBOSS visit here
JBOSS


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

"Parag Sk", please check your private messages for an important administrative matter.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Java property files best practices
 
Similar Threads
JWS and properties file
Best way to handle properties
How to write to a Property file at Run time residing in the WEB-INF
Jar a project with property files in it external to jar
PropertiesFile in Classpath