• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up enviornment variables

 
Mani Natrajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is the best way to implement properties/variables for a Java EE application?
I have an EJB which needs a list of variables whose values are needed for processing in EJB (say for example the JMS servers it needs to publish and various other application specific properties(there are around 50 properties)).
At present, we have a xxx.cfg file which has all the values of these variables put in the server. We hard code this file's path in the EJB and the EJB parses this file to hash the key value pairs and it is used in the application.
I want to remove the code which hard codes the files' path.
Is it better to put this xxx.cfg in the ear of the application or is there any other better/standard way of implementing this?
Your help is greatly appreciated

Thanks
Mani Natarajan
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mani,

your requirement seems to be a good scenario for using simple environment entries: The values are configured in the deployment descriptor and will be injected into the instance variables (directly or by properties). As an example: Futher details/examples can be found in the ejb spec (look for "simple environment entries").
 
Mani Natrajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the response. Injection seems to be a good option, i thought of this option too.
But what if i add a new Enterprise bean , should i be writing the same code to get those variables again in the new EJB?
and update the descriptor for the new EJB/S also?


Thanks
Mani

 
Tejas Aryan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the cfg file updated regularly ?
Can you try binding the "pathtofile" to jndi ?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"winners champ"

Please click on the "My Private Messages" link on top of this page, for a message from JavaRanch.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mani Natrajan wrote:
I have an EJB which needs a list of variables

Mani Natrajan wrote:
But what if i add a new Enterprise bean , should i be writing the same code to get those variables again in the new EJB? and update the descriptor for the new EJB/S also?

First of all I would clear about the nature of my data: Is it data special for each ejb or is it data that is shared among several ejb's ? Not until then you'll be able to make a good design decision.

Simple environment entries are designed for and belong to a bean's environment. So each ejb needs its own deployment descriptor. Variables, properties and DI itself could be placed into a separate class from that the ejb's inherit.

But if there are many ejb's that need the data it might be more appropriate to use something like a singleton bean. In this case the simple environment entries approach could be used for the singleton bean and the other beans could access the data from the singleton bean.
 
Mani Natrajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ralph,
Thanks for the response. The information should be available to several EJBs.

Thanks
Mani
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!