通过TomEE加服务器连接到POJO?

时间:2014-11-20 08:12:14

标签: java tomcat servlets pojo tomee

我在Eclipse Kepler EE中创建了一个Dynamic Web Project,将它连接到Tomee plus 1.7.1服务器并创建了一个servlet和一个POJO。因此,打开浏览器并尝试对类执行某些操作后,servlet按预期工作,但POJO返回错误404.

实际代码是这样的:

// servlet

public class MyServlet extends HttpServlet {  
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
      PrintWriter out = response.getWriter();  
      out.println("I'm a servlet.");  
   }  
}  

// web.xml

<servlet>  
    <servlet-name>MyServlet</servlet-name>  
    <servlet-class>package.MyServlet</servlet-class>  
</servlet>  
<servlet-mapping>  
    <servlet-name>MyServlet</servlet-name>  
    <url-pattern>/MyServlet</url-pattern>  
</servlet-mapping>  

所以当我输入&#34; localhost:8080 // MyServlet&#34;我得到了预期的&#34;我是一个servlet。&#34;信息。问题在于POJO:

// POJO

@Path("/MyPOJO")  
public class MyPOJO {  
   @GET  
   public String get() throws IOExeption {  
      return "I'm a POJO.";  
   }  
}  

我对web.xml文件中的那个类一无所知。我有这门课,我不知道它的作用:

 @ApplicationPath("/sth")  
    public class ApplicationConfig extends Application {      
        @Override  
        public Set<Class<?>> getClasses() {  
            return new HashSet<Class<?>>(Arrays.asList(MyPOJO.class));  
        }  
    }

应用程序是来自M2_REPO \ javax \ ws \ rs \ javax.ws.rs-api \ 2.0.1 \ javax.ws.rs-api-2.0.1.jar的类

所以当我输入&#34; localhost:8080 // sth / MyPOJO&#34;时,我得到错误404,没有例外没有日志。我试过调试,但它没有遇到任何断点。

也许它与我启动服务器时遇到的异常有关:

Nov 19, 2014 6:44:50 PM org.apache.myfaces.ee6.MyFacesContainerInitializer onStartup 
INFO: Added FacesServlet with mappings=[/faces/*, *.jsf, *.faces] 
Nov 19, 2014 6:44:51 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig 
INFO: Reading standard config META-INF/standard-faces-config.xml 
Nov 19, 2014 6:44:51 PM org.apache.myfaces.webapp.AbstractFacesInitializer initFaces 
SEVERE: An error occured while initializing MyFaces: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/> 
java.lang.IllegalStateException: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/> 
at org.apache.tomee.myfaces.TomEEAnnotationProvider.getAnnotatedClasses(TomEEAnnotationProvider.java:43) 
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:90) 
at org.apache.myfaces.config.DefaultFacesConfigurationProvider.getAnnotationsFacesConfig(DefaultFacesConfigurationProvider.java:152) 
at org.apache.myfaces.config.DefaultFacesConfigurationMerger.getFacesConfigData(DefaultFacesConfigurationMerger.java:91) 
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:416) 
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:370) 
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73) 
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:143) 
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119) 
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
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.run(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at java.lang.Thread.run(Unknown Source) 

Nov 19, 2014 6:44:51 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom 
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [162] milliseconds. 
Nov 19, 2014 6:44:59 PM org.apache.myfaces.ee6.MyFacesContainerInitializer onStartup 
INFO: Added FacesServlet with mappings=[/faces/*, *.jsf, *.faces] 
Nov 19, 2014 6:44:59 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig 
INFO: Reading standard config META-INF/standard-faces-config.xml 
Nov 19, 2014 6:44:59 PM org.apache.myfaces.webapp.AbstractFacesInitializer initFaces 
SEVERE: An error occured while initializing MyFaces: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/> 
java.lang.IllegalStateException: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/> 
at org.apache.tomee.myfaces.TomEEAnnotationProvider.getAnnotatedClasses(TomEEAnnotationProvider.java:43) 
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:90) 
at org.apache.myfaces.config.DefaultFacesConfigurationProvider.getAnnotationsFacesConfig(DefaultFacesConfigurationProvider.java:152) 
at org.apache.myfaces.config.DefaultFacesConfigurationMerger.getFacesConfigData(DefaultFacesConfigurationMerger.java:91) 
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:416) 
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:370) 
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73) 
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:143) 
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119) 
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
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.run(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at java.lang.Thread.run(Unknown Source) 

我尝试添加server.xml文件中缺少的行,但服务器根本没有启动。

当我的大学试图在他的PC上运行它时,它适用于POJO和Servlet。我们无法找到任何原因导致它无法在我的电脑上运行。

1 个答案:

答案 0 :(得分:0)

终于有效了。我不得不重新下载TomEE +。也许我的版本错了。