• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Error in EJB

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All I am new to this EJB concept,
I have successfully deployed the EJB, but when i execute the Client I am getting the below error please give a solution for this.
-->
package EJB;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.naming.Context;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import java.lang.*;

public class myClient extends JFrame
{
public static int w=500;
public static int h=95;
public static String str = "Polaris Welcomes You";
public static String value1, value2;
Container cnr;

JLabel lblNumber1, lblNumber2, lblResult;
JTextField txtNumber1, txtNumber2;
JButton butAdd;
public myClient()
{
super(str);
cnr = getContentPane();
cnr.setLayout(new GridLayout(3, 3, 2, 2));
lblNumber1 = new JLabel("Number 1:");
lblNumber2 = new JLabel("Number 2:");
lblResult = new JLabel("Result");
txtNumber1 = new JTextField(10);
txtNumber2 = new JTextField(10);
butAdd = new JButton("Add");
cnr.add(lblNumber1);
cnr.add(txtNumber1);
cnr.add(lblNumber2);
cnr.add(txtNumber2);
cnr.add(lblResult);
cnr.add(butAdd);
butAdd.addActionListener(new addEvent());
setSize(w, h);
show();
}

public static void main(String args[])
{
new myClient();
}

public class addEvent implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
int num1 = Integer.parseInt(txtNumber1.getText());
int num2 = Integer.parseInt(txtNumber2.getText());
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL,
"http://localhost:8080");
Context initialContext = new InitialContext(env);
Context iContext = new InitialContext();
Object obj = iContext.lookup("java:comp/env/ejb/myEJBClass");
myHome home = (myHome)PortableRemoteObject.narrow(obj, EJB.myHome.class);
myRemote remote = home.create();
int res = remote.myMethod(num1, num2);
lblResult.setText("Result Is: " + Integer.toString(res));
}
catch(NamingException e)
{
System.out.println(e);
e.printStackTrace();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
}
}
<--

Exception in thread "main" java.lang.NoClassDefFoundError: myClient (wrong name:
EJB/myClient)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
C:\Dhinakar\Programs\Java\EJB>java EJB.myClient > err.txt
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterp
rise.naming.SerialInitContextFactory. Root exception is java.lang.ClassNotFound
Exception: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
49)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at EJB.myClient$addEvent.actionPerformed(myClient.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
64)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

  •  
    ranger
    Posts: 17346
    11
    Mac IntelliJ IDE Spring
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Dhinikar,
    I am going to move this thread to the, more appropriate, EJB forum. This forum is for Servlets questions.
    You will get a much better response form that forum.
    Mark
     
    Ranch Hand
    Posts: 977
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    the class, com.sun.enterprise.naming.SerialInitContextFactory is missing for the client classpath. You'll have to check your classpath and put the classes the client need under it's classpath, usually you do this setting a environment variable or running some script before running the client.
    regards.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic