我想在TomEE Plus和Eclipse中使用一個帶有web應用程序項目的EJB項目。我可以在Web應用程序項目中使用無界面Bean,但是當我創建新的EJB項目時,在Web應用程序上配置構建路徑以包含EJB項目,TomEE將無法啓動。如何在TomEE Plus/Eclipse中使用Web應用程序項目創建/設置/使用EJB項目?
我將TomEE設置爲在Eclipse的TomEE屬性的服務器位置窗格中使用Tomcat安裝。如果我不這樣做,我甚至無法訪問與Servlet相同的包中的EJB。
的代碼很簡單:
package mypackage;
import java.io.IOException;
// Package containing remote interface and bean implementation
// Remaining imports omitted
import beans.* ;
@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB
HelloSBNoI hb ; // The bean located within this project (same package as servlet)
@EJB
HelloBeanRemote hbfejb ; // The bean located in an ejb project
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html"); ;
response.getWriter().write("Hello From Servlet <br />");
response.getWriter().write("Hello From EJB in same package" + hb.from());
response.getWriter().write("<br />Hello From EJB in different project" +
hbfejb.sayHelloEJB());
}
}
和這裏的TomEE試圖啓動,但未能:
Jul 21, 2014 1:24:47 PM org.apache.catalina.core.ContainerBase startInternal SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/useremoteejb]] at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252) at java.util.concurrent.FutureTask.get(FutureTask.java:111) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/useremoteejb]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 7 more
產生的原因:java.lang.NoClassDefFoundError:Lbeans/HelloBeanRemote;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
at java.lang.Class.getDeclaredFields(Class.java:1760)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:400)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
at org.apache.tomee.catalina.OpenEJBContextConfig.configureStart(OpenEJBContextConfig.java:113)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:371)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: java.lang.ClassNotFoundException: beans.HelloBeanRemote
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.tomee.catalina.LazyStopWebappClassLoader.loadClass(LazyStopWebappClassLoader.java:143)
... 22 more
我花了幾個小時試圖弄清楚什麼看起來像一個簡單的配置錯誤!
預先感謝您的專家幫助