RE: Client program for simple EJB tutorial
Errrg... I sent this yesterday... it doesn't appear to have made it to the list. I hope it still helps: Put the orion.jar file in your classpath as part of the manifest. This allows you to include any file that sits outside of your jar. Example: Manifest-Version: 1.0 Main-Class: com.blah.gui.control.UIFactory Class-Path: log4j.jar jai_core.jar jai_codec.jar orion.jar -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of John D. Ware Sent: Monday, April 01, 2002 4:10 PM To: Orion-Interest Subject: Re: Client program for simple EJB tutorial Hi, This is indeed a timely question as I am working on this also. I was able to get a client working until I tried to put it into a jar file. I get a ClassNotFoundException looking for the com.evermind.server.ApplicationInitialContextFactory when starting my app using: java -cp "c:/orion/orion.jar" -jar pet-class.jar Again, it works fine (Note: no classpath specified) if run like: java org.jdware.pet.client.PetClient any ideas? thanks john ware
RE: Client program for simple EJB tutorial
I don't think -cp and -jar can be used together like that. Try just using -cp and place the .jar on the classpath. > -Original Message- > From: John D. Ware [mailto:[EMAIL PROTECTED]] > Sent: Monday, April 01, 2002 3:10 PM > To: Orion-Interest > Subject: Re: Client program for simple EJB tutorial > > > Hi, > This is indeed a timely question as I am working on this > also. I was able to get a client working until I tried to put > it into a jar file. > I get a ClassNotFoundException looking for the > com.evermind.server.ApplicationInitialContextFactory when > starting my app using: > > java -cp "c:/orion/orion.jar" -jar pet-class.jar > > Again, it works fine (Note: no classpath specified) if run like: > > java org.jdware.pet.client.PetClient > > any ideas? > > > thanks > > john ware > > >
Re: Client program for simple EJB tutorial
Hi, This is indeed a timely question as I am working on this also. I was able to get a client working until I tried to put it into a jar file. I get a ClassNotFoundException looking for the com.evermind.server.ApplicationInitialContextFactory when starting my app using: java -cp "c:/orion/orion.jar" -jar pet-class.jar Again, it works fine (Note: no classpath specified) if run like: java org.jdware.pet.client.PetClient any ideas? thanks john ware
Re: Client program for simple EJB tutorial
Hi Ken - Here's a sample client program. Cheers Ray = import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import mypackage.MyEntityEJB; import mypackage.MyEntityEJBHome; import java.util.Collection; import java.util.Iterator; public class SampleMyEntityEJBClient { public static void main(String [] args) { SampleMyEntityEJBClient sampleMyEntityEJBClient = new SampleMyEntityEJBClient(); try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"); env.put(Context.SECURITY_PRINCIPAL, "user"); env.put(Context.SECURITY_CREDENTIALS, "password"); env.put(Context.PROVIDER_URL, "ormi:///"); Context ctx = new InitialContext(env); MyEntityEJBHome myEntityEJBHome = (MyEntityEJBHome)ctx.lookup("MyEntityEJB"); MyEntityEJB myEntityEJB; // Use one of the create() methods below to create a new instance for (int i=1; i<100; i++) { System.out.println(i); myEntityEJB = myEntityEJBHome.create( new Integer(i).toString() ); } } catch(Throwable ex) { ex.printStackTrace(); } } } --- Ken Cooper <[EMAIL PROTECTED]> wrote: The http://www.orionserver.com/tutorials/orion-primer";>The Orion Primer uses a servlet as a client for an EJB. Does someone have the code for a 'command line' client. That is, a client that is a standard java app (public static void main...)? Have tried this but have had 'problems'. Thanks - Ken-- Kenneth Cooper, Jr. [EMAIL PROTECTED] -- Send and receive Hotmail on your mobile device: Click Here __ Do You Yahoo!? Yahoo! Greetings - send holiday greetings for Easter, Passover http://greetings.yahoo.com/
Re: Client program for simple EJB tutorial
Ken, Your timing is impecable. I just got done figuring out how to get a client program (static void main) up and running about four weeks ago. The message below is the message I sent another individual that was having problems as well. He's said that the document I put together worked perfectly the first time around. Everything I've detailed below is basically doing the 'CabinBean' example from O'Reilly publishings 'Enterprise JavaBeans' book. I'd be happy to fill in the blanks if you get stuck on anything. Let me know how it works for you: ejb-jar.xml=== There seems to be some issues with security role mapping, that I'm stilltrying to figure out. I had to remove the tags fromthis file or else I'd get an exception that admin was not allowed to executeany of the methods on this bean. I'm working on setting up a for admin, but am having some difficulty. It works ifyou leave those out though. Also, make note that the ejb-name is 'CabinBean'. This comes into playlater. JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd"> This Cabin enterprise bean entity represents a cabin on a cruiseship. CabinBean com.titan.cabin.CabinHome com.titan.cabin.Cabin com.titan.cabin.CabinBean Container com.titan.cabin.CabinPK False id name deckLevel ship bedCount This role represents everyone who is allowed full access to the cabin bean. everyone application.xml===Application 1.2//EN" "http://java.sun.com/j2ee/dtds/application_1_2.dtd"> Cabin cabin.jar users application-client.xml=== This is required for the application client 'Client_1.class'. This existsin a META-INF directory where the Client_1.class is being executed from.Notice the ejb-ref-name is 'ejb/CabinBean'. This should be the same as theejb-name in ejb-jar.xml, with the 'ejb/' in front of it. Application Client 1.2//EN""http://java.sun.com/j2ee/dtds/application-client_1_2.dtd"> Cabin client The cabin client program for testing ejb/CabinBean Entity com.titan.cabin.CabinHome com.titan.cabin.Cabin Client_1.class== This is the client program from O'Reilly publishing 'Enterprise JavaBeans'book. Notice a couple things: (1) Instead of using a function called 'getInitialContext', I justinstantiate new InitialContext(). You of course need a jndi.properties filethat can be found in the classpath upon startup with the requiredinformation. I'll provide this a bit later. (2) When I do the lookup. I do: Object ref = jndiContext.lookup("java:comp/env/ejb/CabinBean"); Where as the book does: Object ref = jndiContext.lookup("java:comp/env/ejb/CabinHome"); It SHOULD be the ejb-name you supplied in the ejb-jar.xml file. This wasone of the big reasons it could never find my bean. import com.titan.cabin.CabinHome;import com.titan.cabin.CabinPK;import com.titan.cabin.Cabin; import javax.naming.InitialContext;import javax.naming.Context;import javax.naming.NamingException;import java.rmi.RemoteException;import java.util.Properties; /** * * @author joeman * @version */public class Client_1 { public static void main(String argv[]) { try { Context jndiContext = new InitialContext(); Object ref = jndiContext.lookup("java:comp/env/ejb/CabinBean"); CabinHome home =(CabinHome)javax.rmi.PortableRemoteObject.narrow(ref, CabinHome.class); Cabin cabin_1 = home.create(1); cabin_1.setName("Master Suite"); cabin_1.setDeckLevel(1); cabin_1.setShip(1); cabin_1.setBedCount(3); CabinPK pk = new CabinPK(); pk.id = 1; Cabin cabin_2 = home.findByPrimaryKey(pk); System.out.println(cabin_2.getName()); System.out.println(cabin_2.getDeckLevel()); System.out.println(cabin_2.getShip()); System.out.println(cabin_2.getBedCount()); } catch (java.rmi.RemoteException re) { re.printStackTrace(); } catch (javax.naming.NamingException ne) { ne.printStackTrace(); } catch (javax.ejb.CreateException ce) { ce.printStackTrace(); } catch (javax.ejb.FinderException fe) { fe.printStackTrace(); } } //public static Context getInitialContext() throwsjavax.naming.NamingException { // Properties p = new Properties(); // p.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.ApplicationClientInitialContextFactory"); // p.put(Context