Loading Properties
In my aplication i need configurable properties from a properties file and amexploring which is the best way
1. I can store them in a properties file, say, ABC.properties, using a static class or a Singleton to a access the properties.
2. Use a ResourceBundle?
Which is the preferred way of loading configurable parameters in a J2EE Application from above two ways ?
Besides how can i avoid restarting or redeploying server to load file.?
Thanks
prince wrote:
In my aplication i need configurable properties from a properties file and amexploring which is the best way
1. I can store them in a properties file, say, ABC.properties, using a static class or a Singleton to a access the properties. You can.
2. Use a ResourceBundle?If the propertiesfile is localized, you can consider it. Else it's unnecessary.
Besides how can i avoid restarting or redeploying server to load file.?Several ways: 1) reload file on every call. 2) reload file on specific call. 3) spawn a daemon thread which reloads the file at certain time intervals.
Similar Messages
-
WSAD : loading properties file from EBJ project
Hi,
I am trying to load properties file contains database parameters into my EJB project. I am using WSAD as IDE tool
can you please help me with following.
1. where to place the .properties file physically ?
2.how to load the file to my EJB/DAO classes
3.can i use the same location to place log4j.properties file as well ?
I have tried doing in different ways but none is working.
thank you
Narendragot it working , for information pl go to the following page and section "Using log4j in an EJB Application"
i have followd same steps for loading my properties file .
http://sys-con.com/story/?storyid=43413&DE=1 -
Can I use property loader in a main sequence to load properties in subsequence?
Hi, I have been trying to use the property loader to load test limits and local variabels into subsequences from the main sequence.
I can export all the properties for my main sequence and all the subsequences contained within by selecing <all sequences> in the export function.
When I try to load the exported file back in using the property loader I get differant errors depending on the format I exported/imported it with.
For text or csv files iget error -17100
"The file format is incorrect near the section 'StationGlobals'. Make sure that you are using start and end markers correctly."
For an xl format I get error -18
"Property loader step failed to import or export properties.
310 property value(s) were found.
43 property value(s) were imported from 920 row(s) of data"
There is no where near 920 rows of data or 320 properties in the exported file.
If i use the property loader to load properties in just main it works fine, is there extra formating I need to do to the file before importing it or is it not possible to load properties into a subsequence from a property loader in main?
Solved!
Go to Solution.Hi,
I have tried several sequences and building the propertyloader file using the export tool,
Moving the End_Mainsequence to the bottem did not help.
I can load values into a single sequence with no problem it is only when I try to load properties into a sub sequence from the main sequence that I have issues.
Attached is a more simple example of what I am trying to acheive.
Kind regards,
Hugo
Attachments:
Sequence File 2.seq 9 KB
Test.csv 2 KB -
Loading properties in JAR directory
I am trying to load properties files that are in the directory structure of the JAR file. The first properties object loads, but subsequent properties objects will not load. The code is as follows:
public Properties loadProperties(String file_name)
InputStream data = null;
Properties props = null;
try
data = getClass().getResourceAsStream(file_name);
//if(data==null) exit("ERROR: "+file_name);
props = new Properties();
props.load(data);
data.close();
data = null;
catch(Exception e)
handleException(e, file_name);
if(DEBUG)
printline("Property Loaded Successfully: " + file_name);
printline(props.toString());
return props;
the file names have the following setup
/directory/subdir1/subdir2/subdir3/file_name
The code works fine when not JAR'd - any suggestions?If your program is in an executeable jar file then add the following in the manifest
class-path: junk.jar
junk.jar has
pjb/props/myconfig.properties file
To access the properties in junk from your executable jar file in your class, do the following
Locale eng = Locale.ENGLISH;
String myvalue = java.util.ResourceBundle.getBundle("pjb.props.myconfig",eng).getString("greeting");That should work
Or if you not using an executable jar file just set your CLASSPATH to the directory where that junk.jar is.
java -cp c:\myjavalib\stash\ <-----Assmuing junk.jar is in thereJava dynamically reads jar files. -
Exception while loading properties from an xml file
Hi all,
I've got a problem while loading properties from an XML file:
java.lang.ClassCastException: org.apache.xerces.dom.DeferredCommentImpl cannot be cast to org.w3c.dom.Element
ERROR - Cannot load properties from the specified file <./conf/login.prop> java.lang.ClassCastException: org.apache.xerces.dom.DeferredCommentImpl cannot be cast to org.w3c.dom.Element
at java.util.XMLUtils.importProperties(XMLUtils.java:97)
at java.util.XMLUtils.load(XMLUtils.java:69)
at java.util.Properties.loadFromXML(Properties.java:852)
at g2.utility.HRPMProperties.<init>(HRPMProperties.java:78)
at g2.utility.HRPMProperties.getInstance(HRPMProperties.java:94)
at g2.gui.workers.ApplicationSwingWorker.<init>(ApplicationSwingWorker.java:36)
at g2.main.Main.main(Main.java:37)but this code worked before, and I've got the xerces and xercesImpl packages in the classpath, anyone can give me an hint on how to fix the problem?Here there's the code that instantiates the HRPMProperties object loading the property file:
public class HRPMProperties extends Properties {
* A reference to myself.
protected static HRPMProperties mySelf = null;
* The property file to which load the configuration.
protected static String propertyFile = "./conf/login.prop";
* A set of static strings used as keys in the properties file.
public final static String DATABASE_URL = "database_url";
public final static String DATABASE_USERNAME = "database_username";
public final static String DATABASE_PASSWORD = "database_password";
public final static String REAL_USERNAME = "real_username";
public final static String REAL_PASSWORD = "real_password";
public final static String PHANTOM_LOGIN = "login_thru_phantom_user";
public final static String AUTOCONNECT = "autoconnect";
public final static String TRANSLATION_FILE = "translation_file";
* Builds up an empty properties map.
protected HRPMProperties(){
super();
this.reload();
* Builds up the property map from the specified input file. <B> The file must be in XML format</B>.
* In case of exception and/or problems reading from the specified file, an empty property map is returned.
* @param fileName the path and the name of the file with the XML representation of the properties.
protected HRPMProperties(String fileName){
super();
try{
this.loadFromXML(new FileInputStream(fileName));
}catch(Exception e){
Logger.error("Cannot load properties from the specified file <"+fileName+"> " + e);
e.printStackTrace();
* Provides an instance of the property class loaded from the default configuration file.
* @return the property instance
public static final HRPMProperties getInstance(){
if( HRPMProperties.mySelf != null )
return HRPMProperties.mySelf;
else{
HRPMProperties.mySelf = new HRPMProperties(HRPMProperties.propertyFile);
return HRPMProperties.mySelf;
}The constructor is the one triggering the exception, so there's a problem loading the XML property file. -
Bug in OWB 10gR2: Several Loading Properties after sync
Hi,
we recognize a possible bug in owb, can anybody please approves this behaviour?
Every column of a table in an owb mapping has fourr loading properties:
- Load Column When Updating Row (YES/NO, default YES)
- Match Column When Updating Row (YES/NO, default NO)
- Load Column When Inserting Row (YES/NO, default YES)
- Match Column When Deleting Row (YES/NO, default NO)
These properties are stored as a record in the repository and references the column. If you change one of the values, this record will be updated in the repos. But if you do a "synchronize" for the table, you get a second record - for each sync one more! Updates changes only the latest record!
If you copy a mapping (using "Cut"/"Copy" and "Paste") or do an import/export the owb uses not the latest record, he choose one of them by chance. So you cannot easily reproduce this error and the mappings probably don't do what they should.
What are your experiences - do you recognize this too?
Regards,
Detlef
Edited by: dapel on Oct 20, 2008 12:10 PMUpdate:
The sync process essentially creates orphaned records within the repository which unfortunately get exported/imported into the next repository, making it random which child detail record gets imported last. This phenomenum is what makes the "Yes/No" attributes somewhat unpredictable. OWB 10.2.0.4 includes a bugfix for this.
There is a cleanup script from oracle for existing repositories I have attached this script with the caveat that you should make a complete repository backup before proceeding. This script also allow you to run it in "test-only" mode to see how many bad records will be removed.
Script:
http://rapidshare.com/files/156472039/FIX_OWB_REPO.sql.html
Regards,
Detlef -
How to load properties inner Jdeveloper
Hello,
I'm trying to load properties from some file using something like this
"final URL in = this.getClass().getResource("/jfreereport.resources");"
But this allways returns me null, so this Mean that my properties file was not loaded, I tried add this file to my classpath (throught project properties), and when I run my classpath has the file but my application is not capable to locate my properties, why??
How is the exactly procedure to load this properties files??
Thanks in advanc
Mauricio AlarconTry something like:
Properties props = new Properties();
try
InputStream in = ClassLoader.getSystemResourceAsStream("/jfreereport.resources");
props.load(in);
in.close();
catch(Exception ex)
//do something
} -
Failed to load properties from server. Please try again
I'm getting this message from the win32, in the property dialog
window.
"failed to load properties from server. Please try again"
In june 1 2001, thread was created
http://forums.oracle.com/forums/message.jsp?id=442131
The last message was
According to the metalink admin, this issue describes a known
bug with no current fix.
Was this not fixed in 1.2 for win32?
MitchI'm getting this message from the win32, in the property dialog
window.
"failed to load properties from server. Please try again"
In june 1 2001, thread was created
http://forums.oracle.com/forums/message.jsp?id=442131
The last message was
According to the metalink admin, this issue describes a known
bug with no current fix.
Was this not fixed in 1.2 for win32?
Mitch -
All,
We are using PO 7.4 with SP5, and we have an issue while accessing URL Exchange profile page (http://<host:port>/webdynpro/dispatcher/sap.com/com.sap.xi.exprofui/XIProfileApp) it throw's the below error.
dbconnect.prop: failed to load properties file .\dbconnect.properties
dbconnect.prop: failed to load properties file
Did some one seen this before and have resolved ? Any help is highly appreciated.
Thank you, PranayThough below note is not applicable to you, i would suggest you to check if the destination is created by the configuration wizard? If not you can create one and see if it helps.
Create Java RFC destination XI_EXCHANGE_PROFILE manually: Navigate to http://[host]:[port]/nwa --> Configuration --> Infrastructure --> Destinations. Create the RFC Destination with PILDUSER as logon user.
1525193 - PI CTC: Exchange Profile Access after (EhP) Upgrade -
Hi
I can't load properties file. Please help!
my setting is listed as follows:
My properties file "kpggc.properties" is stored in the path : W:\kpggc\KPGGCWorkspace\KPGGCProject\src\hkpost\kpggc\client\resources
I have already add the above path into the classpath and my application is a standalone application. I use the following codes to load the "kpggc.properties" file:
private static boolean getProperties()
Properties properties = new Properties();
try
properties.load(new FileInputStream("kpggc.properties"));
catch (IOException e)
System.out.println("Cannot find the properties file 'kpggc.properties'");
catch (Exception e)
System.out.println(e.getMessage());
After running the above method, error message "Cannot find the properties file 'kpggc.properties'""always show.
Thanks in advance.there is a way. u need not give the complete path of ur file.
include the path of the properties file in ur classpath.
in ur code, do the following:
(inputStream and properties are declared before this code.)
inputStream = ClassLoader.getSystemResourceAsStream(fileName);
properties.load(inputStream);
regards -
Hi All,
Pls explain how I can assign the loading properties for the dimension tables. For instance what properties I need to set for a surrogate key, natural key and other attributes. Pls let me know for all the 3 types of slowly changing dimensions.
If any reference material is available with examples discussing the above properties, it will be very much useful.
Thanks very much,
Regards
KishanGood afternoon Kishan,
Check this doc: http://otn.oracle.com/sample_code/products/warehouse/files/SCDWhitePaper.zip
Also check these threads:
maintain history in DW
Slowly Changing Dimension Type 2 - Bound name for MATCHING
Good luck, Patrick -
Unable to load properties file from filesystem
Hi,
I have a client swing-applicatiion packaged in a jar-file. The application uses some resource files, including a xxxx.properties file to set defaults for the application. All resource files are included in the jar file and everything works as expected. I load the xxxx.properties file as follows:
is_ = getClass().getResourceAsStream("/resources/xxxx.properties");
Because it is not possibl to change any property values inside the jar-file without recreating this jar-file, i want to exclude the xxxx.properties file from the jar-file and put it in the folder containing the jar-file.
So i have:
drive:/folder/app.jar
drive:/folder/xxxx.properties
Now i read the xxxx.properties file from disk in stead of the 'resouce'-folder within my application (jar):
is_ = getClass().getResourceAsStream("drive:/folder/xxxx.propoerties");
but it doesn't work, the file isn't found.
What am i missing here?
Any suggestions?The best way to approach this is to include the properties file in the Jar as you originally did. If the user changes any property, save the entire set of properties to a sub-directory of user.home (perhaps based on the package name of the main class). Check for the copy in user.home before using the 'default' properties built into the Jar.
Other places/ways to store the changed information.
- java.util.prefs.Preferences
- Assuming the app. has a GUI and can be deployed over a network, the JNLP API PersistenceService. Here is a demo. of the PersistenceService (http://pscode.org/jws/api.html#ps).
Edit 1:
I did not at first notice that this post was in Java Applet Development.
<li> Applets can also (theoretically) use cookies to store information. This is prone to failure when users disable cookies.
<li> To store information on the local file system (e.g. in user.home) or to use Preferences (AFAIU) would require trusted code.
<li> If the user has the Next Generation Java Plug-In (Java 1.6.0_10+) it is possible to leverage the JNLP API services in an embedded & sand-boxed applet.
Edited by: Andrew Thompson on Feb 1, 2011 9:32 AM -
Can't load properties from file in webapp
I've got a bean that I use to read a properties file. from the JSP page, I use
<%@ page import="com.buildrequest.Login" %>
<jsp:useBean id="buildproperties" scope="page" class="com.buildrequest.BuildProperties" />
<jsp:setProperty name="buildproperties" property="*" />
Within the bean, I try to load it as a classloader resource, only to have it throw an IllegalArgumentException, saying it cannot load the file.
I've put the file in with the bean java source in com.buildrequest, and have tried "buildrequest.properties", "/com/buildrequest/buildrequest.properties", and nothing worked.
Outside of the JSP page, it works fine using the path "/com/buildrequest/buildrequest.properties", and reports back the properties included.
Where do I need to put the properties file so that the bean can find it within the context of the JSP page?
Thanks for any help!Dave,
I reckon you're on the right track... just have to figure out "what's the path to properties file"... I suspect you've got a context problem... not sure... I'm pretty new at this stuff myself.
So, what's your development environment? O/S, IDE, app/web-server, etc.
Cheers. Keith. -
Can ResourceBundle load .properties from files and .jar?
Hi Guys,
I'm trying to I18N an application with ResourceBundle.
Suppose my class look like this:
package pack;
import java.util.ResourceBundle;
public class MyClass {
public static void main(String[] args) {
ResourceBundle rb = ResourceBundle.getBundle("Language");
}This would load the localized string from Language.properties
And when I pack the class file and Language.properties into a jar. It works fine
But what I tried to do is to make the ResourceBundle try to load from external file first
before it load from the jar file so that if I have a new language file I can just drop in the
NewLang.properties.
Inside .jar file look like this
/Language.properties
/pack/MyClass.class
/meta-inf/Manifest.mf
I tried look into some forum and they suggest to include Class-Path in Manifest.mf file
to include current path like this
Class-Path: .
But still, it didn't work. If I include .properties in .jar it will not look outside but if I didn't include
any .properties it found a properties file.
How can I achieve this ?Dave,
I reckon you're on the right track... just have to figure out "what's the path to properties file"... I suspect you've got a context problem... not sure... I'm pretty new at this stuff myself.
So, what's your development environment? O/S, IDE, app/web-server, etc.
Cheers. Keith. -
Webservice - loading properties file
Hi,
I'm creating a webservice which connects to server A, sends a message M and gets a response message R back. The values to connect to server A are in a properties file which I need to load in the webservice. Since I connect to the same server everytime, (i just send diff messages and get appropriate response back) I just want to load the properties file just once. I don't want to load the properties file everytime the webservice gets called so I can improve the performance. Can you please tell me how I would be able to achieve this? I'm planning to deploy this webservice on to a tomcat server.If you enable CDI in your tomcat then you can use an @ApplicationScoped bean to hold the values.
Another option is to use a caching library like ehcache. -
Hello Everyone,
We are experiencing difficulties when trying to load a properties file from a directory other then the one where the servlet is located. We are using the following code for this purpose:
private final String PROP_FILE_NAME = "my.properties";
Properties props = new Properties();
try {
props.load(getClass().getResourceAsStream(codeBase + PROP_FILE_NAME));
} catch(IOException e) {
//handle error ...
where codeBase is either physical directory path to the properties file or the URL. In either case we get a NullPointer exception which means that file is not found. But when we copy the properties file into the same directory where the servlet resides, everything works fine.
Does anybody have an idea as to how to resolve our problem?
Any help will be greatly appreciated!
Thanks in advance!
Y.M.HI,
I always keep my properties in a sub-directory called resources. In this case it is called Aircraft.properties.
* Holds the ResourceBundle of this object.
private static ResourceBundle resources;
static
try
resources = ResourceBundle.getBundle("resources.Aircraft", Locale.getDefault());
catch (MissingResourceException mre)
System.err.println("resources/Aircraft.properties not found");
System.exit(1);
// Here I pick up the data from the properties file
protected String getResourceString(String nm)
String str;
try
str = resources.getString(nm);
catch (MissingResourceException mre)
str = null;
return str;
// In this case I use menubar as key to my properties
String[] menuKeys = tokenize(getResourceString("menubar"));
Hope this will help a bit.
Klint
Maybe you are looking for
-
My current work around is turning java on and off, but all fields are still not active. Please advise. Thank you.
-
IDVD 5 - Make DVD to play immediately without a start button or theme
Is there a procedure within iDVD 5 that will allow me to not choose a theme and to cause the burned DVD to play the video/audio content immediately upon being placed in a DVD player for playback?
-
Problems with java.util.zip
I've got a odd problem here. I'm not sure if this is the appropriate forum but I couldn't find anyplace more appropriate. So the problem is... I create my ZIP file and if I open it in WinZip, no problem. But if I open the ZIP file using the 'Compress
-
EJB3 newbie - when to use EJB?
If I just want to build a reusable module that does not have any business critical actions, such as a login module, or a blog module, should I use EJB? Also, am I correct that only EJBs can run on distributed servers, and that all other non-EJB compo
-
Centering text onto an image.
How do you do it? For example g.drawImage(image, x, y, Graphics.HCENTER | Graphics.VCENTER); g.drawString("text", x, y, Graphics.HCENTER | Graphics.BOTTOM);does not work, I could try all different variations of positions; Top, Bottom, Vcenter, Hcente