• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Stuck In the Mud with First EJB

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.naming:org.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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
Jaz Chana
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic