This happens to be my first post here, but was around from quite some time. Today I decided to register and start interacting with all you knowledgeable people. I am very new to world of programming and know nothing much. I have recently migrated an application from JBoss 4.4.2 to 5.1.0. I have configured the queues and ports correctly. The app. is getting deployed correctly. But the issue is with reading a props folder(Contains property files) which resides in the EAR bundle. In JBoss 4.2.2 it was running fine because this.Class.getResource() was getting it from tmp folder, here the EAR is getting expanded. But I have noticed that in newer version i.e 5.1.0 the props folder isnt getting expanded. Its trying to read from the EAR bundle itself and throws a FileNotFound Exception. I deployed the EAR in Exploded format and the it works fine. I wanted to know the best way to overcome this scenario. One option is to read EAR using JarFile, JarEntry but I guess that is not a good practice. That would mean code changes in an application which is well tested. Can someone suggest a better way to overcome this scenario??
There is a props folder which contains all the property files which is just inside the EAR. It’s not in jar or war within the EAR. “Application.ear/props/” is where all the property files reside. Then we have “Application.ear/ABC.war/” and then “Application.ear/META-INF/” and “Application.ear/elib/”(All jars are placed here in elib folder).
And the code for reading the property file is:
All I need is to read the file from “Application.ear/props/<FileName>.registry”.
If I recall correctly, the base directory of an EAR file is no longer automatically in the classpath for the EAR. You will have to place the properties file into a JAR file and place that in the lib directory within the ear.
Joined: Jul 24, 2011
Many thanks for taking efforts and replying.
I tried doing that. I put that props folder in the jar and placed that in the lib directory within the ear. But still it doesn't seem to be finding it. Sir, as I said I am new to this programming world. I know that I am doing it the wrong way. Can you please provide a code snippet to read property files??
Lets forget the structure of my EAR bundle. Suppose we are making a new application and we have a lot of property files to be read at run time by our application. What is the ideal way of doing that? Can you please provide a sample EAR structure and a few lines of code to read those property files? Also it should be done in such a way that the bundle would work on all versions of JBoss and even on others like WebLogic.
Using ClassLoader.getResource(), or any of its variations, is the correct way to load a resource. But be aware that naming a resource is like naming a class; that is, you don't use directory names with slashes, but rather package names with dots.
For example, a file within a JAR at props/my.properties would be accessed as "props.my.properties".