• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB lookup after deploying to Jboss - Help  RSS feed

 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I'm deploying a simple HelloWorld(Bean) to the jboss as following steps:
1)Declare Remote statless session bean interface HelloWorld
2)Construct a implementation class named HelloWorldBean to implement the Remote interface with annotation @Stateless, and there is a method sayHello
3)Compile and make it jar files and then deploy it to jboss server
4)Start jboss server
5)Code the client class named TestHelloWorld

A error occurred when I used following code:



But, if I used the following code it do not occur again:


Would somebody help me please? It confused me serveral days. In one word, I want to use Annotation instead of explicitly ejb-jar.xml etc just existed in EJB2.x but it seems not work correctly.

Thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you discovered the JMX-Console in JBoss yet? Run Jboss and got to localhost:8080/jmx-console. This will give you a view of the JNDI name space. You can check whether there is anything bound with the context "HelloWorldBean/remote". If there isn't, presuming your EJB actually deployed, then it shouldn't take long to find out where it was really bound.
 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Have you discovered the JMX-Console in JBoss yet? Run Jboss and got to localhost:8080/jmx-console. This will give you a view of the JNDI name space. You can check whether there is anything bound with the context "HelloWorldBean/remote". If there isn't, presuming your EJB actually deployed, then it shouldn't take long to find out where it was really bound.


Anyway, thanks so much for your reply. Please go through to learn more details:

Yes, the bean itself has been deployed to the Jboss server successfully. What I'm concerning is the way former one can not work by which the server will throws the exception:


But once I use the Hashtable and fragment like the later one, it will work correctly.

I just not know the difference between these two methods since EJB3.0 has annouced not to need deployer like ejb-jar.xml

Awaiting your reply.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the default constructor of InitialContext(), it searches for a file (named jndi.properties) which contains the lookup information. And if the tjndi.properties file is not found in the classpath, then you will see the exception, that you are currently seeing. Have a look at NoInitialContextException for more details.

Now, when you specify the lookup properties using the Hashtable in your code, the jndi.properties file is not searched for in the classpath. And that's why the code works.
 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:
When you use the default constructor of InitialContext(), it searches for a file (named jndi.properties) which contains the lookup information. And if the tjndi.properties file is not found in the classpath, then you will see the exception, that you are currently seeing. Have a look at NoInitialContextException for more details.

Now, when you specify the lookup properties using the Hashtable in your code, the jndi.properties file is not searched for in the classpath. And that's why the code works.


I modified the jndi.properties in $JBOSS_HOME$\server\default\config and then restarted the server but at last it still not worked.

Awaiting for your more help.

Thanks so much!
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Luo:


I modified the jndi.properties in $JBOSS_HOME$\server\default\config and then restarted the server but at last it still not worked.

Awaiting for your more help.

Thanks so much!


No. That file should not be changed it is used to do local lookups within JBoss server. You must revert that file back to the way it was.

You need a seperate jndi.properties file, and it should be with the client archive file in the root of its classpath.

Mark
 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:


No. That file should not be changed it is used to do local lookups within JBoss server. You must revert that file back to the way it was.

You need a seperate jndi.properties file, and it should be with the client archive file in the root of its classpath.

Mark


Sorry, I'm new one in EJB. Would you like to show me the concrete steps on processing it? I'll be grateful of you if you list the place where the jndi.properties should be put etc.

Thanks again for your help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I can't really tell you which directory but if you have this kind of layout


c:\myproject\src\com\mycompany

and you set your classpath to c:\myproject\src then that is the directory that the jndi.properties file.

Richard you need to put your last name back into your display name to keep with the JavaRanch Naming Policy of using your real first and real last names.

Thanks
 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
Well I can't really tell you which directory but if you have this kind of layout


c:\myproject\src\com\mycompany

and you set your classpath to c:\myproject\src then that is the directory that the jndi.properties file.

Richard you need to put your last name back into your display name to keep with the JavaRanch Naming Policy of using your real first and real last names.

Thanks


Hi Mark,

Thank you so much!

I redeploy it and follow your instruction finally it works properly.

In addition, I put back my last name now.

Cheers!
 
Richard Luo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, thank you all for helping me to solve this problem.

You guys are all warm-hearted and this forum is really excellent one!

 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Luo:
Again, thank you all for helping me to solve this problem.

You guys are all warm-hearted and this forum is really excellent one!



You are very welcome. We have also been in your shoes before, and while after a while you might find where you put the jndi.properties is a trivial thing, but when you fist start to learn, it is never trivial and we will be there. Wherever there is injustice, we will be there, whenever there is a cat stuck in a tree, we will be there. Whenever, there is a new episode of Battlestar Galactica, I will be there. Sorry digression alert.

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!