Need help with simple EAR application (EJB 3 + STRUTS 2 + Glassfish)

Hello everyone!

I am trying to learn how to develop enterprise applications with EJB 3 + STRUTS 2 + glassfish (and eclipse).

I wanted to have a very simple application (helloworld like) but i am having problems with the EAR package configuration and how to access my bean from my web layer...

=====================================================

I have 2 projects, EJB_test and WEB_test and the classes i have are

** EJB LAYER **

package source;

import java.rmi.RemoteException;

import javax.ejb.Remote;

@Remote

publicinterface HelloWorldService{

public String getMessage()throws RemoteException;

}

AND

package source;

import java.rmi.RemoteException;

import javax.ejb.Stateless;

@Stateless

publicclass HelloWorldServiceBeanimplements HelloWorldServiceLocal{

public String getMessage()throws RemoteException{

return"don抰 worry buddy it is just a test?;

}

}

** WEB LAYER **

package application.test;

import javax.ejb.EJB;

import source.HelloWorldServiceBean;

import com.opensymphony.xwork2.ActionSupport;

publicclass ShowDataextends ActionSupport{

private String message;

public String execute()throws Exception{

setMessage(bean.getMessage());

return SUCCESS;

}

publicvoid setMessage(String message){

this.message = message;

}

public String getMessage(){

return message;

}

@EJBprivate HelloWorldServiceBean bean;

publicvoid setBean(HelloWorldServiceBean bean)

{

this.bean = bean;

}

}

AND my web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>Struts Blank</display-name>

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

i think the struts.xml and the index.jsp are ok (i tested it before adding the ejb)

For the EAR project, i tried

<?xml version="1.0" encoding="UTF-8"?>

<application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">

<display-name>

EAR_TEST</display-name>

<module id="WebModule_1181435330640">

<web>

<web-uri>WEB_TEST.war</web-uri>

<context-root>WEB_TEST</context-root>

</web>

</module>

<module>

<ejb>EJB_TEST.jar</ejb>

</module>

</application>

But i get a The deployment descriptor of the module 'EJB_TEST.jar' cannot be loaded.

and if i try to deploy the web and the ejb alone i get a

java.lang.NoClassDefFoundError: Lsource/HelloWorldServiceBean;

Btw, is that

@EJB private HelloWorldServiceBean bean; in my web layer correct? (i added the ejb_test project as a required project to the web project)... it seems to be wrong but i couldnt figure out how to put all that together

thx in advance

[5837 byte] By [Lemmericha] at [2007-11-27 6:57:00]
# 1
For loading jar, you need to have ejb-jar.xml also which will define location of ejb class files( remote and ejb). I think this is the reason for not loading jar.
gssa at 2007-7-12 18:34:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
But shoudn't the ejb-jar.xml be optional for EJB 3?
Lemmericha at 2007-7-12 18:34:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Yes, ejb-jar.xml is optional for EJB 3.

I can see a few problems with the code. First, the client programming model is based on the

bean's business interface, not the bean class.The client should not reference the bean class at all.

If the business interface it needs is HelloWorldService, the @EJB would be :

@EJB

private HelloWorldService helloWorldEjb;

Also, where is the assocation between your remote business interface and the bean class?

The bean class in your code snippet implements HelloWorldServiceLocal rather than

HelloWorldService.It's not clear whether you want to implement both or if it's a typo.

ksaksa at 2007-7-12 18:34:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...