File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes MBean InitialContext() Tomcat query- what is the relation 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
Reply locked New topic
Author

MBean InitialContext() Tomcat query- what is the relation

Ravi Gupt
Greenhorn

Joined: Oct 16, 2007
Posts: 17
Hi,

I created and deployed an MBean in my tomcat. It uses datasource to connect to DB.
My questions is:

When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails.

Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor).

When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception:

avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]

I invoked hello method of MBean from JConsole.


Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time.

Thanks
Ravi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Please UseOneThreadPerQuestion. Let's continue here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MBean InitialContext() Tomcat query- what is the relation