Solved

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

Posted on 2008-10-22
5
3,279 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now