File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes JBOSS 5.1.0 issue with props folder in an EAR. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JBOSS 5.1.0 issue with props folder in an EAR." Watch "JBOSS 5.1.0 issue with props folder in an EAR." New topic
Author

JBOSS 5.1.0 issue with props folder in an EAR.

Vijendra Prakash
Greenhorn

Joined: Jul 24, 2011
Posts: 4
Hello friends,

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??

Thanks.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Viren, welcome to Java Ranch!

Exactly where is you properties file located within your EAR file? If within a JAR or WAR within the EAR, where is that JAR/WAR, and where in that is the properties file.

Also post the code you are using to access the properties file and provide the values of any variables used (the value passed to getResources() is the most critical piece.)

Also, please see you private messages regarding an important administrative matter.


JBoss In Action
Vijendra Prakash
Greenhorn

Joined: Jul 24, 2011
Posts: 4
Hi Peter,

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”.

Thanks.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

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.
Vijendra Prakash
Greenhorn

Joined: Jul 24, 2011
Posts: 4
Hi Peter,

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.

Thanks.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

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".

Here are some more details:
http://www.coderanch.com/t/89900/JBoss/reading-properties-file
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JBOSS 5.1.0 issue with props folder in an EAR.