aspose file tools*
The moose likes Tomcat and the fly likes Configuring JNDI for JavaBean in Tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring JNDI for JavaBean in Tomcat 5" Watch "Configuring JNDI for JavaBean in Tomcat 5" New topic
Author

Configuring JNDI for JavaBean in Tomcat 5

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Hello,
I am trying to configure "resource factory" for JavaBean so that i can access it through JNDI insead of instantiating it directly. I read the JNDI Resources HOW-TO and other documents. I still could not get it working. Here is what i have and the exceptions that i get.



Here is my web.xml



I didn't find context section in server.xml like mentioned in step 4 in HOW-TO. so i created a separate context.xml like this:



and finally, here are my codes that access the Account Bean:



The line it is specially having a problem is:



Any suggestion would be greatly appreciated. Thanks.
[ May 17, 2005: Message edited by: Brian Smith ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
You have a typo in your context.xml file, you are missing an enclosing double-quotes:

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Thanks for pointing the typo. I fixed that and still having the same exception. Please help me. Thanks.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
A couple of questions:

1. What is the location of your context.xml?
2. Does the com.rndBeans.Account.class conform to the JavaBeans naming conventions i.e. no-arg contructor?
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Hello Craig,

Originally posted by Craig Jackson:
A couple of questions:

1. What is the location of your context.xml?


It is in ${Tomcat_Home}/conf folder.

2. Does the com.rndBeans.Account.class conform to the JavaBeans naming conventions i.e. no-arg contructor?


Yes. The Account class does have a no-arg constructor.


I am still getting the same exception. However, I don't have any exception being thrown in the log file though.I am wondering If I have to do configure anything in the server.xml file as well which I am not sure HOW.

Appreciate your help. Thanks.
[ May 17, 2005: Message edited by: Brian Smith ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
1. What is the location of your context.xml?
It is in ${Tomcat_Home}/conf folder.


The context.xml should be placed in your META-INF directory of your web application. The resources defined in the context.xml will only be available to applications for a particular web application.



Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Just a reminder to stop and restart TOMCAT after you re-deploy your web application.
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Thanks for you constant posting to help me but still could not get it working. Like you advised, i created the context.xml file as show below:


and put it in:



I am still getting the same exception!!! I don't know what I am doing wrong..
[ May 17, 2005: Message edited by: Brian Smith ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
How are you deploying your web application?

1. Did you create a new war(web application archive) called JNDIRnD.war(which contains the META-INF/context.xml etc).

2. Then drop it into the $CATALINA_HOME/webapps directory

3. Did you delete the existing $CATALINA_HOME/webapps/JNDIRnd directory or optionally use Tomcat's manager web page to re-deploy JNDIRnD

4. Stop and Re-start Tomcat only if you just deleting the existing JNDIRnD directory.


Another suggestion, did you check the console or catalina.out log file for any errors dealing with your application?
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Originally posted by Craig Jackson:
How are you deploying your web application?

1. Did you create a new war(web application archive) called JNDIRnD.war(which contains the META-INF/context.xml etc).

2. Then drop it into the $CATALINA_HOME/webapps directory

3. Did you delete the existing $CATALINA_HOME/webapps/JNDIRnd directory or optionally use Tomcat's manager web page to re-deploy JNDIRnD

4. Stop and Re-start Tomcat only if you just deleting the existing JNDIRnD directory.


Another suggestion, did you check the console or catalina.out log file for any errors dealing with your application?


No I didn't create the WAR file. I just create a context.xml file and put it in /webapps/JNDIRnD/META-INF folder. And then re-started Tomcat but still get the same exception. The exact same line is throwing exception as was throwing intitally.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Stop Tomcat and restart it, while it is re-starting check the console or log file carefully, to see if Tomcat found any errors.

Maybe, we are missing something simple here, but I can't see why it doesn't work.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Also can you post the full error stack messages?
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Neither Console nor Log has any exceptions being thrown while Tomcat starts up. Here is the exception stack:



Here's the context lookup codes:



I have no clue what's missing here. could be any of the followings:

- server.xml --- i didn't even touch it
- web.xml
- context.xml - any of the attributes of <context> tag
- any configurations or locations beside above?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I created a small test using the BeanFactory.

Testing:
1. I removed any reference to the web-context from %catalina_home%\webapps\hello* prior to each test.

2. I created my war file hello.war:



3. I placed my war file in %catalina_home%\webapps. You can verify that tomcat as successfully deployed your application by viewing the console or log file.

4. Tested results:
http://localhost:8080/hello/servlet/HelloWorldExample
Browser displayed "Hello Mr Jackson".

Context.xml:


MyBean.java:


HelloWorldExample.java:
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
I have done exactly the same thing you did with Eclipse. When i deploy it, everything gets put in the right place but does not seem to be working for some reason. weired..i gave it up for now until this weekend. thanks for your help Craig.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuring JNDI for JavaBean in Tomcat 5