• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Learning EJB3 on JBOSS 4.22

 
Sagar Kale
Ranch Hand
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rabin,

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

Regards

Sagar
 
Roland Thomas Lichti
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic