Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant EJB会话bean未绑定在JBoss 5的EAR封装中_Ant_Jboss_Ejb_Ear - Fatal编程技术网

Ant EJB会话bean未绑定在JBoss 5的EAR封装中

Ant EJB会话bean未绑定在JBoss 5的EAR封装中,ant,jboss,ejb,ear,Ant,Jboss,Ejb,Ear,我有一个动态web项目,我以EAR格式部署在JBoss5上。我使用ant在应用服务器上编译和部署ear文件。若我独立地部署EJB和war客户机,那个么一切都可以工作,但当我尝试在ear中打包时,会话bean并没有绑定。我的EJB代码和clientWeb在同一个项目中,我的项目中并没有独立的EJB模块。我尝试将jar添加到WEB-INF库中的业务接口之外,甚至ear文件的lib目录中,但没有任何效果。我想知道EJBJAR是否不在类路径中,以及如何设置ear文件中模块的顺序 application.

我有一个动态web项目,我以EAR格式部署在JBoss5上。我使用ant在应用服务器上编译和部署ear文件。若我独立地部署EJB和war客户机,那个么一切都可以工作,但当我尝试在ear中打包时,会话bean并没有绑定。我的EJB代码和clientWeb在同一个项目中,我的项目中并没有独立的EJB模块。我尝试将jar添加到WEB-INF库中的业务接口之外,甚至ear文件的lib目录中,但没有任何效果。我想知道EJBJAR是否不在类路径中,以及如何设置ear文件中模块的顺序

application.xml

    <?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
  <display-name>X3</display-name>
  <module>
    <web>
      <web-uri>x3.war</web-uri>
      <context-root>x3</context-root>
    </web>
  </module>
  <module>
        <ejb>x3.jar</ejb>
    </module>
</application>
业务逻辑

package com.lmd.dev.ejb.session;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.lmd.dev.ejb.domain.Student;

/**
 * Session Bean implementation class ManageStudentSessionBean
 * 
 * @author Sameera Jayasekara
 */
@Stateless
public class ManageStudentSessionBean implements ManageStudentSessionBeanLocal {

 @PersistenceContext
 private EntityManager entityManager;

 public boolean addStudent(Student student) {
     System.out.println("Trying .............");
  entityManager.persist(student);
  return true;
 }

}
Servlet客户端

package com.lmd.dev.controller;

import java.io.IOException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lmd.dev.ejb.domain.Student;
import com.lmd.dev.ejb.session.ManageStudentSessionBeanLocal;

/**
 * 
 * 
 * 
 */
public class ManageStudentServlet extends HttpServlet {

 private static final long serialVersionUID = 1L;

 @EJB(mappedName="ManageStudentSessionBean/local")
 private ManageStudentSessionBeanLocal manageStudentSessionBeanLocal;

 public void init(ServletConfig config) throws ServletException {

  super.init(config);

 }

 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

 }

 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

  String message = "";

  String firstName = request.getParameter("fname");
  String lastName = request.getParameter("lname");
  String email = request.getParameter("email");

  Student student = new Student();
  student.setFirstName(firstName);
  student.setLastName(lastName);
  student.setEmail(email);

  if (manageStudentSessionBeanLocal != null && manageStudentSessionBeanLocal.addStudent(student)) {
      message = "Student Successfuly Added";
  } else {
      message = "Student Adding Failed";
  }

  request.setAttribute("message", message);
  RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
  rd.forward(request, response);

 }

}
Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>x3</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ManageStudentServlet</display-name>
    <servlet-name>ManageStudentServlet</servlet-name>
    <servlet-class>com.lmd.dev.controller.ManageStudentServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ManageStudentServlet</servlet-name>
    <url-pattern>/ManageStudentServlet</url-pattern>
  </servlet-mapping>
</web-app>
您也可以在git上找到源代码


当我们从EJB模块中打包一个EAR文件时,客户机的查找方法会略有变化。我们总是可以在控制台中检查注入应该参考的路径

@EJB(mappedName="YOUR_EAR_NAME/ManageStudentSessionBean/local")

您是否尝试过将@Statelessname=manageStudentSessionBean添加到EJB模块,而不仅仅是@Stateless,并且在servlet中,在条目private ManageStudentSessionBeanLocal ManageStudentSessionBeanLocal=null上方使用注释@EJBname=ManageStudentSessionBeanLocal;谢谢你的帮助,但遗憾的是它没有起作用。ejb模块是否进入类路径?你知道,当我试图通过在war的类路径中添加ejb模块来独立部署war和ejb模块时,它就可以工作了。我不相信它需要进入类路径。您是否在WAR的web-INF文件夹中有一个web.xml文件,正如在web模块中进行注入的链接文章所述,您的web.xml应该使用2.5版本的web应用程序xsd-您可以尝试使用重要部分中显示的xml创建该文件吗?@JGlass我在问题中添加了web.xml结构,是的,它使用2.5版本。我认为客户端应该在类路径中有ejb模块,以便在web.xml上部署和编译。我相信有了JBoss类加载器,EJB模块已经在类路径中了——您是指将其作为类补丁条目添加到web应用META-INF/MANIFEST.MF文件中吗?我的所有项目都没有这个清单,但其中有许多项目正在升级到JBoss7。部署应用程序时,server.log文件中会显示哪些输出?
package com.lmd.dev.ejb.session;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.lmd.dev.ejb.domain.Student;

/**
 * Session Bean implementation class ManageStudentSessionBean
 * 
 * @author Sameera Jayasekara
 */
@Stateless
public class ManageStudentSessionBean implements ManageStudentSessionBeanLocal {

 @PersistenceContext
 private EntityManager entityManager;

 public boolean addStudent(Student student) {
     System.out.println("Trying .............");
  entityManager.persist(student);
  return true;
 }

}
package com.lmd.dev.controller;

import java.io.IOException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lmd.dev.ejb.domain.Student;
import com.lmd.dev.ejb.session.ManageStudentSessionBeanLocal;

/**
 * 
 * 
 * 
 */
public class ManageStudentServlet extends HttpServlet {

 private static final long serialVersionUID = 1L;

 @EJB(mappedName="ManageStudentSessionBean/local")
 private ManageStudentSessionBeanLocal manageStudentSessionBeanLocal;

 public void init(ServletConfig config) throws ServletException {

  super.init(config);

 }

 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

 }

 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

  String message = "";

  String firstName = request.getParameter("fname");
  String lastName = request.getParameter("lname");
  String email = request.getParameter("email");

  Student student = new Student();
  student.setFirstName(firstName);
  student.setLastName(lastName);
  student.setEmail(email);

  if (manageStudentSessionBeanLocal != null && manageStudentSessionBeanLocal.addStudent(student)) {
      message = "Student Successfuly Added";
  } else {
      message = "Student Adding Failed";
  }

  request.setAttribute("message", message);
  RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
  rd.forward(request, response);

 }

}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>x3</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ManageStudentServlet</display-name>
    <servlet-name>ManageStudentServlet</servlet-name>
    <servlet-class>com.lmd.dev.controller.ManageStudentServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ManageStudentServlet</servlet-name>
    <url-pattern>/ManageStudentServlet</url-pattern>
  </servlet-mapping>
</web-app>
@EJB(mappedName="YOUR_EAR_NAME/ManageStudentSessionBean/local")