I have to following code to try to connecting to a EJB I wrote.
I have no problem compiling this client program, but when I run it using the
java command on the command prompt, I get the error message saying
C:\Program Files\Allaire\JRun\servers\default\shopping>java ControllerApp
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ejb/EJBHome
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
It complains not being able to find javax.ejb.EJBHome. But I have import
javax.ejb.*; in my client program as show in the code below and I have also
import javax.ejb.*; in my Home Interface file. I also wrote a 10 lines
program to try to import the javax.ejb.EJBHome; and I can compile and run
this program without any error message, so I have got my classpath set
correctly. Now I have no idea why it cannot find javax/ejb/EJBHome? Any
ideas would help. :)
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.ejb.*;
import java.rmi.*;
import ejbeans.*;
public class ControllerApp {
private static Context _context;
public static void main(String argc[]) {
//String group_id = req.getParameter("group_id");
int group_id = 1;
Collection items_collection;
/*final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"allaire.ejipt.Contex
tFactory");
properties.setProperty(Context.PROVIDER_URL,"ejipt://"+server+":2323");
properties.setProperty(Context.SECURITY_PRINCIPLE,user);
properties.setProperty(Context.SECURITY_CREDENTIALS,password);
try {
_context = new
IntialContext(properties);
} catch (Exception e) {
}*/
try {
_context = new InitialContext(); //NEW
} catch (Exception e) {
}
try {
final DatabaseHome home = (DatabaseHome)
_context.lookup("shopping.DatabaseHome");
final Database database =
home.create();
items_collection =
database.findByGroup(group_id);
if ( items_collection != null ) {
System.out.println("Can get items
collection");
} else {
System.out.println("Cannot get items
collection");
}
} catch (RemoteException re) {
} catch (Exception e) {
}
}
}
Anthony Mak
==========================
Anthony Mak ([EMAIL PROTECTED])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists