File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB Deployment Descriptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Deployment Descriptor" Watch "EJB Deployment Descriptor" New topic
Author

EJB Deployment Descriptor

Ryan P. Kane
Greenhorn

Joined: Jun 18, 2004
Posts: 16
Hello,

What's the easiest way to provide an EJB data like a JDBC driver, a database's URL, and a database's username and password without hard coding those parameters into the EJB? I think it has something to do with the <resource-ref> tag, but I am having a little trouble figuring this one out. I'm familiar with doing this in the Web Container with web.xml, but not with EJBs. Anyhow, if someone could help me out with an example, I'd really appreciate it. Thanks!

Ryan Kane
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
HI,



Add the above lines into your config.xml if u are using Weblogic as your application server.
I suggest you make these changes by going into the admin domain.



-------
Atul
Ryan P. Kane
Greenhorn

Joined: Jun 18, 2004
Posts: 16
I guess I need to further specify what I'm looking for. I used the JDBC parameters as an example, but I'm really just looking for a way to pass all sorts of configuration parameters to an EJB, not just JDBC specifics. Even if I create a Connection Pool and a DataSource, I'm still hard coding the JNDI context name into the code, and I'd like to avoid that. Is there something equivalent to config.getInitParam("paramName") in a servlet? I guess I could create a set method for the parameters, but then I'm reliant upon clients executing that set method prior to running any methods that might require the parameters.

Thanks for your help,

Ryan
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
Hi Ryan,

I think you should be clear with hard coding.
For a given piece of code which is dependent on some external parameters, and if these external parameters is present in your code then its called hard coding.

Regarding EJB , the container takes care of maintaining a connection pool. It only needs a JNDI name. Specifying a JNDI name in your code is not called hard coding. If tommorrow u change your database or driver u should not compile ur code.


Is there something equivalent to config.getInitParam("paramName") in a servlet



Above you are mentioning "paramName" , is it not hard coding w.r.t to your understanding.

Regards
Atul
Ryan P. Kane
Greenhorn

Joined: Jun 18, 2004
Posts: 16
OK, with paramName, that can be configured externally in web.xml. Yes the paramName is hard coded, but its value can be changed from the web.xml file thus preventing code changes. You recommend using JNDI, which is great, but doesn't solve my problem. Here's why:



So in the above example I have three things that I consider "hard coded". Number one is the url to the JNDI tree, number two is the INITIAL_CONTEXT_FACTORY value of "weblogic.jndi.WLInitialContextFactory", and number three is the DataSource with the value of "jhuDataSource". I'm new to EJB, but they are supposed to be distributable and configurable right?. I thought for sure there would be a way to supply these pieces of information to my EJB without hard coding, but now I'm not sure. In a servlet or JSP you use the web.xml file to supply parameters like these. Can you do this with EJB?

Ryan
prem karun gopal
Greenhorn

Joined: Dec 03, 2003
Posts: 24
Hi,
This has nothing to do with EJB.You simply write all your parameters eg ;hostname,JNDI name ,poolname etc in an xml format.Then read it and pass those values for you context lookup.


Prem Kumar.k<br />Email :write2premk@yahoo.com
Ryan P. Kane
Greenhorn

Joined: Jun 18, 2004
Posts: 16
This has a lot to do with EJB, and I found out how to do it. In the deployment descriptor, you can specify parameters as follows:

<enterprise-beans>

<session>
<ejb-name>RegistrationStatus</ejb-name>
<home>srs.ejb.StatusHome</home>
<remote>srs.ejb.Status</remote>
<ejb-class>srs.ejb.StatusBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>jdbcDriver</env-entry-name>
<env-entry-type>java.lang.String </env-entry-type>
<env-entry-value>COM.cloudscape.core.JDBCDriver</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>jdbcUrl</env-entry-name>
<env-entry-type>java.lang.String </env-entry-type>
<env-entry-value>jdbc:cloudscape:c:\jhu</env-entry-value>
</env-entry>

</session>

</enterprise-beans>

Then in your code, you can do the following:


[ July 27, 2004: Message edited by: Ryan P. Kane ]
prem karun gopal
Greenhorn

Joined: Dec 03, 2003
Posts: 24
its ok.Whether you do it as ejb ref or use your own xml.It doesnt matter.
The core logic is to define the parameters some where and xml is a good place.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB Deployment Descriptor