File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes ejb myclipse weblogic error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ejb myclipse weblogic error" Watch "ejb myclipse weblogic error" New topic

ejb myclipse weblogic error

raj kiyare

Joined: Apr 21, 2011
Posts: 16
i'm using ejb 2 with myeclipse 9 and weblogic 9 . i'm learning java ee. was trying to use myeclipse.just testing with ejb2 have not yet started ejb3. getting following error when i run my client app.

Exception in thread "main" 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(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at javax.naming.InitialContext.lookup(
at WishClient.main(

my files

import java.rmi.RemoteException;

public interface Wish
extends javax.ejb.EJBObject
public String getMonthName() throws RemoteException;
public String getDayName() throws RemoteException;
public String generateWishMsg(String name) throws RemoteException;

public interface WishHome
extends javax.ejb.EJBHome
// public static final String COMP_NAME="java:comp/env/ejb/Wish";
// public static final String JNDI_NAME="Wish";

public Wish create()
throws javax.ejb.CreateException,java.rmi.RemoteException;


import java.util.*;
import javax.naming.*;
public class WishClient {

public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Hashtable ht= new Hashtable();

InitialContext ic = new InitialContext();
WishHome hor=(WishHome)ic.lookup("WishJndi");
Wish eor=hor.create();
System.out.println("Week Day Name =" +eor.getDayName());
System.out.println("Month Name =" +eor.getMonthName());
System.out.println("Wish Message =" +eor.generateWishMsg("Raj"));


import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.util.*;

public class WishBean implements SessionBean {

/** The session context */
private SessionContext context;

public void ejbCreate(){

public WishBean() {
// TODO Auto-generated constructor stub

public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub


public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub


public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub


public void setSessionContext(SessionContext newContext)
throws EJBException {
context = newContext;

public String getMonthName(){
String months[]=new String[]{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
Calendar cl=Calendar.getInstance();
int m=cl.get(Calendar.MONTH);
return months[m];

public String getDayName(){
String weeks[]=new String[]{"","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
Calendar cl=Calendar.getInstance();
int w=cl.get(Calendar.DAY_OF_WEEK);
return weeks[w];

public String generateWishMsg(String name) throws EJBException {
// rename and start putting your business logic here
Calendar cl=Calendar.getInstance();
int h=cl.get(Calendar.HOUR_OF_DAY);
return "Good Morning" + name;
else if(h<=16)
return "Good Afternoon" + name;
return "Good Evening" + name;



<ejb-jar >
<session >









1. can someone please tell me why i'm getting error. how should i resolve it.
2.when i'm using xdoclet to generate bean, home interface and xml files. it automatically generating jndi name. like this

public static final String COMP_NAME="java:comp/env/ejb/Wish";
public static final String JNDI_NAME="Wish";

so i commented them and used my own jndi name in weblogic -ejb-jar.xml. is it wrong to do that?. how come these variables have me declared in my home interface. why and how are they used. and i did not understand the structure --> java:comp/env/ejb/Wish .. what does it mean?. i'm a newbie . so please explain clearly.
I agree. Here's the link:
subject: ejb myclipse weblogic error
It's not a secret anymore!