Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load external properties files into EJB 3 app running on WebLogic 11

 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am researching the best way to load external properties files from and EJB 3 app whose EAR file is deployed to WebLogic.

Was thinking about using an init servlet but I read somewhere that it would be too slow (e.g. my message handler might receive a message from my JMS queue before the init servlet runs).

Suppose I have multiple property files or one file here:

~/opt/conf/

So far, I feel that the best possible solution is by using a Web Logic application lifecycle event where the code to read the properties files during pre-start:



Found this here

What would happen if the server is already running, would post start be a viable solution?

Can anyone think of any alternative ways that are better?
 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ApplicationLifeCycleListener, as the name indicates, goes with the application, not to be confused with a StartUpClass.

So even if the server is running and your application is deployed but has not been started yet (state: new) the pre-start method will be called once you start your application (i.e. from the Admin Console).

It really depends on when your application expects the properties to be available. If that is on application initialization, the pre-start would be a match. Using post start will execute the method after your application has fully initialized (state: active).

Hope that helps.
Matt
 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for responding, Matt!

Actually, it does load on server start up...

Using Oracle Enterprise Pack for Eclipse, I created an Enterprise Project and named it:

PropertiesDemoEAR

I also created a PropertiesDemoEARWeb module in which I put this code

(inside PropertiesDemoEARWeb / Java Resources / src / com.project.util):



Inside PropertiesDemoEAR/EarContent/META-INF/weblogic-application.xml

Added the following listener declaratively:



Right clicked on the PropertiesDemoEAR / Export / EAR file / Destination:

C:\Oracle\Middleware\user_projects\domains\MyDomain\autodeploy

When I run WebLogic 11g through Eclipse, I get this error message in the console:



Question(s):

(1) What am I possibly doing wrong? Why can't it find my PropertiesFileHandler class?

(2) Is the location (c:/etc/error.properties) of my properties file suitable or should it be inside MyDomain directory?

(3) Is there a default directory or just simple configuration area that WebLogic loads properties files which are accessible to any application that runs in WebLogic?

 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 - your class needs to reside in the APP-INF/classes directory structure inside your EAR file
e.g. APP-INF/classes/com/project/util/PropertiesFileHandler

2 - should work with Properties.load(), not sure though if you can use getResourceAsStream()
with an absolute path as it searches the CLASSPATH

3 - if -Dweblogic.ext.dirs is not set, it defaults to $DOMAIN/lib;$WL_HOME/common/lib/ext;$WL_HOME/server/lib/ext
so if you store error.properties in $DOMAIN/lib it will be on the CLASSPATH and you should be able to load it using
getResourceAsStream("error.properties")

Hope that helps
Matt
 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark,

Got it working... The issue was that I had it set up as web project rather than a Java EE Utility project in Oracle Enterprise Edition for Eclipse.

As a web project, it was putting the .class file inside WEB-INF/classes instead of APP-INF.

Also, needed to put error.properties inside my actual domain.

C:\Oracle\Middleware\user_projects\domains\MyDomain

Will look into -Dweblogic.ext.dirs flag...

Kindest regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic