aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Stuck In the Mud with First EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stuck In the Mud with First EJB" Watch "Stuck In the Mud with First EJB" New topic
Author

Stuck In the Mud with First EJB

Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
I am using the apress 'Beginning Java EE, from Novice to Professional' book. In its first EJB example it attempts to create am extremely simple stateless session bean. I am using jboss application server 4.2.2 and java Runtime Environment, Standard Edition 1.5.0. There are two classes and a remote interface as follows;











The directory structure is;
SimpleSessionApp
|-beans
|-SimpleSession
|-SimpleSessionBean
|-client
|-SimpleSessionClient

The tells you to add the following to your classpath;
set CLASSPATH=.;C:\jboss\lib\concurrent.jar;
C:\jboss\lib\jboss-common.jar;
c:\jboss\client\jboss-j2ee.jar;
c:\jboss\lib\commons-httpclient.jar;
C:\jboss\server\all\lib\jboss.jar;
C:\jboss\server\all\lib\jboss-remoting.jar;
C:\jboss\server\all\lib\jboss-transaction.jar;
C:\jboss\server\all\lib\jnpserver.jar;
C:\jboss\server\all\deploy\ejb3.deployer\jboss-ejb3.jar;
C:\jboss\server\all\deploy\ejb3.deployer\jboss-ejb3x.jar;
C:\jboss\server\all\deploy\jboss-aop.deployer\
jboss-aop.jar;
C:\jboss\server\all\deploy\jboss-aop.deployer\
jboss-aspect-library.jar


The next step is to compile the java source code;
javac -d . client/*.java
javac -d . beans/*.java

After this you create an ejb3 jar;
jar cf SimpleSessionApp.ejb3 beans\*.java
And deploy this jar to your jboss deploy directory while jboss is running. Once this is done you run the client with the following arguments and switches while inside the client directory of SimpleSessionApp;

java
-Djava.naming.factory.initial=
org.jnp.interfaces.NamingContextFactory
-Djava.naming.factory.url.pkgs=
org.jboss.namingrg.jnp.interfaces
-Djava.naming.provider.url=
localhost client.SimpleSessionClient
Now is the time for all good men


After having done all of this I get the following error

Exception in thread "main" java.lang.NoSuchMethodError: main

why is this? This is my first attempt at creating an ejb and I'm totally lost. Any help would be appreciated.

Edited by: Jazman on Feb 19, 2008 2:42 PM
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
The class you are trying to run does not have a main method. Check that the class file you are running really is SimpleSessionClient.class in the client directory.

Also, check that you are not running some other (and incorrect version) of this class. For example, these method signatures would cause the problem you have.







SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
The class definitely has a main method and it is the correct syntax. I am also sure that I am running SimpleSessionClient and not something else.

I've tried to create the project in eclipse and I got the same error. Then I tried to rejig the code a little and my SimpleSessionClient now looks like this;




Instead of providing the various properties at runtime I put them in a HashTable and pass them to the InitialContext constructor. Its now giving me a different error;



javax.naming.NameNotFoundException: SimpleSessionBeans not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:613)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at client.SimpleSessionClient.main(SimpleSessionClient.java:28)

Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Somehow you have overcome your main method problem.

Your new problem occurs possibly because the EJB is not bound into the server's JNDI tree. The JNDI name for the EJB is specified in the jboss.xml deployment descriptor with the jndi-name element.
Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
I thought that by simply deploying the application on Jboss you are adding it to the jndi lookup tree. Assuming this is not the case, how would I go about adding the EJB to the servers jndi tree? I have an application.xml file in my SimpleApp Ear, but it does not contain any jndi information. It looks something like this;


<?xml version="1.0" encoding="ASCII"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<display-name>SimpleSessionApp</display-name>
<module>
<ejb>SimpleSessionBeans.jar</ejb>
</module>
<module>
<java>SimpleSessionClient.jar</java>
</module>
</application>

How should I alter this?
palla sridhar
Ranch Hand

Joined: Oct 15, 2007
Posts: 111
Hi Jaz!
I think there is a problem defining your JNDI lookup.
simpleSession = (SimpleSession) ctx.lookup("SimpleSessionBeans/beans.SimpleSession/remote");

The name of the bean is SimpleSessionBean not "SimpleSessionBeans".

So change the name and try.


Thanks and Regards,
[url]www.techlikes.com[/url]
*Nothing is CONSTANT in life, except CHANGE*
Bojan Tomic
Greenhorn

Joined: Apr 08, 2008
Posts: 25
Since the topic is relatively old, I don't know if the OP still cares, but I had a very similar problem that stemmed from the fact "jar cf SimpleSessionApp.ejb3 beans\*.java" doesn't compile the classes, so I got an *.ejb3 that can not be deployed. I changed the line to "jar cf SimpleSessionApp.ejb3 beans\*.class" and it worked.
 
wood burning stoves
 
subject: Stuck In the Mud with First EJB