-
1. Re: Deployed OK but application client won't run
adrian.brock Feb 12, 2003 11:16 PM (in response to andchri)Try
jar -tf HelloWorld.jar and compare the output with
the name in the error and the package you defined
in the class.
Also, you don't want Sun's j2ee.jar, use jboss-j2ee.jar
Regards,
Adrian -
2. Re: Deployed OK but application client won't run
andchri Feb 13, 2003 6:12 AM (in response to andchri)Thanks for the response Adrian. Here are the contents of HelloWorld.jar:
META-INF/
META-INF/MANIFEST.MF
com/
com/mastertech/
com/mastertech/sample/
com/mastertech/sample/HelloWorld.class
com/mastertech/sample/HelloWorldBean.class
com/mastertech/sample/HelloWorldHome.class
META-INF/ejb-jar.xml
As you can see there is no jboss.xml but going by the tutorial I was following this is not necessary for such a simple example. Here is ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
JBOSS Hello World Wpplication
<display-name>Hello World EJB</display-name>
<enterprise-beans>
<ejb-name>Hello</ejb-name>
com.mastertech.sample.HelloWorldHome
com.mastertech.sample.HelloWorld
<ejb-class>com.mastertech.sample.HelloWorldBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</enterprise-beans>
</ejb-jar>
Here is the application client code:
Note I have not imported the Remote and Home interface as the client is in the same package as the EJB. Not very realistic I know but this was supposed to be a quick sample to get started!
package com.mastertech.sample;
/** application client **/
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class HelloWorldClient{
public static void main(String [] args){
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "LOCALHOST:1099");
env.put("java.naming.factoy.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
try{
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("HelloWorld");
HelloWorldHome home = (HelloWorldHome)
javax.rmi.PortableRemoteObject.narrow(obj, HelloWorldHome.class);
HelloWorld helloWorld = home.create();
System.out.println(helloWorld.sayHello());
helloWorld.remove();
}
catch(Exception e){
e.printStackTrace();
System.out.println("Exception: "+ e.getMessage());
}
}
}
I also took Sun’s j2ee.jar out of the classpath and left in jboss-j2ee.jar in it. Unfortunately I am still getting the same error.
Can anyone spot any mistakes In the above code?
Andrew -
3. Re: Deployed OK but application client won't run
petertje Feb 13, 2003 4:32 PM (in response to andchri)> Can anyone spot any mistakes In the above code?
Yep: you are trying to start HelloWorldClient and that class is not in the jar (according to your listing of the jar contents).
Cheers,
Peter. -
4. Re: Deployed OK but application client won't run
andchri Feb 14, 2003 10:24 AM (in response to andchri)Peter,
The reason there is no HelloWorldClient in the jar is that it is not part of the EJB. It is a stand-alone application client, which I am trying to run directly from the command line.
Thanks for the advice though. Maybe I should try packaging the whole lot in an EAR file.
Andrew -
5. Re: Deployed OK but application client won't run
petertje Feb 14, 2003 5:28 PM (in response to andchri)Hi Andrew,
You are right that there is no need to package the HelloWorldClient in the ear file; however, if you want to run it from the commandline, you have to make sure the class is on the classpath, right?! According to your 1st post, your classpath just contains jboss jars and your HelloWorld.jar, which - according to your 2nd post, just contains the bean classes. That won't work, that's what i was trying to say. Sorry that i didn't make myself clear.
So, just add the HelloWorldClient.class to the classpath mentioned in the 1st post before running the stand-alone client. That should be enough...
Hth
Peter.