Solved

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

Posted on 2008-10-22
5
3,292 Views
Last Modified: 2013-12-15
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
Comment
Question by:fsyed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 475 total points
ID: 22783869

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
 

Author Comment

by:fsyed
ID: 22792958
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
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 25 total points
ID: 22793966
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
 

Author Closing Comment

by:fsyed
ID: 31509090
Thanks so much for your time, my code worked the way it was supposed to.
Take care.
Sincerely;
Fayyaz
0
 

Author Comment

by:fsyed
ID: 22805093
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 151
tomcat startup error 5 167
Glassfish admin console not working 1 88
DTD and JAVA versions 1 55
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question