This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Learning EJB3 on JBOSS 4.22 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Learning EJB3 on JBOSS 4.22" Watch "Learning EJB3 on JBOSS 4.22" New topic
Author

Learning EJB3 on JBOSS 4.22

Sagar Kale
Ranch Hand

Joined: May 02, 2008
Posts: 188
Hi All,

I started learning ejb3 on JBOSS 4.22. I am new to JBOSS. I wrote one session bean and created JAR. I deployed that JAR in JBOSS. But while running client, I got into many ClassNotFoundErrors. I tried to resolve them by finding required JAR and adding it to classpath.

In my following code, I am getting following error.

method sayHello(String name) must override superclass method.

Please help me.

import java.rmi.RemoteException;

import javax.ejb.Stateless;
import com.test.SayHello;

public @Stateless class SayHelloBean implements SayHello {

@Override
public String sayHello(String name) throws RemoteException {
System.out.println("Hello "+name);
return null;
}


}

[ July 17, 2008: Message edited by: Sagar Kale ]
[ July 17, 2008: Message edited by: Sagar Kale ]
Rabin Rath
Greenhorn

Joined: Jul 17, 2008
Posts: 4
I tested this EJB3.0 application in JBoss and it is working so it may help you.

sample interface Calculator.java
/**
*
*/
package com.hcl.ejb.iface;

/**
* @author Administrator
*
*/
public interface Calculator {
public int add(int a,int b);
public float mul(float a,float b);

}
Local Interface CalculatorLocal.java

package com.hcl.ejb.sessionface;
import com.hcl.ejb.iface.*;
import javax.ejb.Local;

@Local
public interface CalculatorLocal extends Calculator{

}

Remote Interface CalculatorRemote.java

package com.hcl.ejb.sessionface;
import com.hcl.ejb.iface.*;
import javax.ejb.Remote;

@Remote
public interface CalculatorRemote extends Calculator{

}

Stateless session bean CalculatorBean.java

package com.hcl.ejb.session.bean;

import com.hcl.ejb.sessionface.CalculatorLocal;
import com.hcl.ejb.sessionface.CalculatorRemote;
import javax.ejb.Stateless;

public @Stateless class CalculatorBean implements CalculatorLocal, CalculatorRemote{

public int add(int a,int b){
return a+b;
}
public float mul(float a,float b){
return a+b;
}
}


Client class CalculatorClient.java

/**
*
*/
package com.hcl.ejb.client;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.hcl.ejb.iface.*;
import com.hcl.ejb.sessionface.*;
import com.hcl.ejb.session.bean.*;

/**
* @author Administrator
*
*/
public class CalculatorClient {

/**
*
*/
public CalculatorClient() {
// TODO Auto-generated constructor stub
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Properties prop=new Properties();
prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.provider.url","jnp://localhost:1099");
prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
InitialContext ctx=new InitialContext(prop);
System.out.println("111");
Calculator cal=(Calculator)ctx.lookup("CalculatorBean/remote");
System.out.println("222");
System.out.println("add: = "+cal.add(10,20));
System.out.println("mul: = "+cal.mul(10.5f,20.5f));

}catch(NamingException ne){
ne.printStackTrace();
}
}

}


make the respective package no need to make it jaar start the server and run the client as right click on the CalculatorClient.java run as java application it will work for you.
Sagar Kale
Ranch Hand

Joined: May 02, 2008
Posts: 188
Thanks Rabin,

Can you please tell me what are the jars should I add in classpath?

Regards

Sagar
Roland Thomas Lichti
Greenhorn

Joined: Jul 19, 2008
Posts: 4
Originally posted by Sagar Kale:
Hi All,

In my following code, I am getting following error.

method sayHello(String name) must override superclass method.

[...]

public @Stateless class SayHelloBean implements SayHello {

@Override
public String sayHello(String name) throws RemoteException {
System.out.println("Hello "+name);
return null;
}


}



Did you try to remove the @Override? As far as I can see, it does not override a method but implements an interface ...

bye,
Roland
Sagar Kale
Ranch Hand

Joined: May 02, 2008
Posts: 188
I tried both with or without @Override

The code gets compiled without any error. But when I run, I get following error which is strange


D:\TestEJB3\src>java com.test.Test
Exception in thread "main" javax.ejb.EJBException: java.lang.RuntimeException: j
ava.lang.Error: Unresolved compilation problem:
The method sayHello(String) of type SayHelloBean must override a superclass method

at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java
:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
Sagar Kale
Ranch Hand

Joined: May 02, 2008
Posts: 188
Sorry,

I did silly mistake, my earlier deployment jar had compilation error. After resolving it, I forgot to create new jar and redeploy.


Sorry and thanks for help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Learning EJB3 on JBOSS 4.22