This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 152
VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic