• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3302
  • Last Modified:

Trying to deploy HelloWorld EJB3 app using Eclipse 3.3 and JBoss 4.2 Application Server

Dear Fellow Java Developers:

I am going through the book, "EJB3 in Action" written by Debu Panda, and am trying to deploy the source code in eclipse 3.3 (europa) using JBoss 4.2 application server.  Right now, I am trying to deploy the "Hello World" application from chapter 1 and am having some difficulty.  
(source code may be downloaded from: http://www.manning.com/panda)   I was able to run the code as described in the book by using Ant, however, I would like to be able to run the code within eclipse.  I am able to deploy the application (I created a project called ejbHelloWorld, and an ejbModule underneath it that contains two packages:

1.  com.ejb3inaction.actionbazaar.buslogic;  This package holds the HelloUser Interface, as well as the HelloUserBean class
2.  package com.ejb3inaction.actionbazaar.client;  This package holds the HelloUserClient class which calls the above EJB.  The code for the client, interface, and EJB3 are attached.

I deploy the application using the "Run on Server" wizard, and choose JBoss as my server of choice.  I then add "ejbhelloworld" to the JBoss 4.2 server as a configured project.  From there is where I am confused.  How do I run it?  I try to select the application and choose Run As ->Application, but then I get the following error:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.ejb3inaction.actionbazaar.client.HelloUserClient.main(HelloUserClient.java:21)

How do I correct this?  What am I doing wrong?  I have tried to run the package holding just the client code, and I get the same error.  What do I do?

Thanks to all who respond.
Sincerely;
Fayyaz


//Below is the remote interface
 
package com.ejb3inaction.actionbazaar.buslogic;
 
import javax.ejb.Remote;
 
@Remote
public interface HelloUser {
	public void sayHello(String name);
}
 
 
//Below is the code for the EJB3 stateless session bean
package com.ejb3inaction.actionbazaar.buslogic;
 
import javax.ejb.Stateless;
 
@Stateless
public class HelloUserBean implements HelloUser {
	public void sayHello(String name) {
		System.out.println("Hello " + name + " welcome to EJB 3 In Action!");
	}
}
 
//Below is the code for the client
package com.ejb3inaction.actionbazaar.client;
 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
 
import com.ejb3inaction.actionbazaar.buslogic.HelloUser;
import com.ejb3inaction.actionbazaar.buslogic.HelloUserBean;
 
public class HelloUserClient {
	private static HelloUser helloUser;
 
	public static void main(String[] args) {
		try {
			Context context = new InitialContext();
			helloUser = (HelloUser) context.lookup("chapter1/"
					+ HelloUserBean.class.getSimpleName() + "/remote");
			helloUser.sayHello("Curious George");
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
}

Open in new window

0
fsyed
Asked:
fsyed
  • 3
2 Solutions
 
Dejan PažinHead of SW DevelopmentCommented:

You should define the Context like this (localhost and 1099 are very probably what you have, if not, change appropriately to your server):

Hashtable env = new Hashtable();
env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
env.put("java.naming.provider.url","localhost:1099");

Context ctx = new InitialContext(env);
0
 
fsyedAuthor Commented:
Thanks very much for your response, your solution worked!  Can you explain to me what it is that I am doing by adding your code block into my client code, and why it's necessary?  As I said, I was able to run the previous code as is using ant and jboss alone, by I am interested in knowing why this is necessary when using eclipse.  Will I be needing this block of code for future EJB3 projects in eclipse and JBoss?   Just wondering.

Thanks again.
Sincerely;
Fayyaz
0
 
chaitu chaituCommented:
Can you explain to me what it is that I am doing by adding your code block into my client code, and why it's necessary?

may be this link will help you.
http://www.informit.com/articles/article.aspx?p=28281

Will I be needing this block of code for future EJB3 projects in eclipse and JBoss?
yes..
0
 
fsyedAuthor Commented:
Thanks so much for your time, my code worked the way it was supposed to.
Take care.
Sincerely;
Fayyaz
0
 
fsyedAuthor Commented:
Thanks very much for your solutions.  My code worked exactly as I wanted it to.  Thanks also for that article, although it's a bit dated, it does cover material that was relevant to this topic.

Take care.
Sincerely;
Fayyaz
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now