Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

843830Jun 10 2007 — edited Jun 12 2007
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
public interface HelloWorldService {
	
	public String getMessage() throws RemoteException;

}

AND

package source;

import java.rmi.RemoteException;

import javax.ejb.Stateless;

@Stateless
public class HelloWorldServiceBean implements HelloWorldServiceLocal {
	
	public String getMessage() throws RemoteException {
		return "don�t worry buddy it is just a test�";
	}

}
** WEB LAYER **
package application.test;

import javax.ejb.EJB;

import source.HelloWorldServiceBean;

import com.opensymphony.xwork2.ActionSupport;

public class ShowData extends ActionSupport {

	private String message;
	
	public String execute() throws Exception {
		
	    setMessage(bean.getMessage());
		return SUCCESS;
	}
	
    public void setMessage(String message){
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
            
    @EJB private HelloWorldServiceBean bean;
    
    public void 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2007
Added on Jun 10 2007
3 comments
366 views