java吧 关注:1,235,798贴子:12,703,677
  • 8回复贴,共1

【求助】关于freemarker与tomcat的一个小问题

取消只看楼主收藏回复

事情是这样的我创建一个java web项目使用freemarker,运行时tomcat启动不了,楼下附代码与错误日志


1楼2017-03-28 16:15回复


    2楼2017-03-28 16:19
    回复
      三月 28, 2017 4:17:44 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
      警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FreemarkerTest3' did not find a matching property.
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Server version: Apache Tomcat/8.0.42
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Server built: Mar 8 2017 19:58:16 UTC
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Server number: 8.0.42.0
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: OS Name: Windows 10
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: OS Version: 10.0
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Architecture: amd64
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Java Home: C:\Program Files\Java\jdk1.8.0_112\jre
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: JVM Version: 1.8.0_112-b15
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: JVM Vendor: Oracle Corporation
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: CATALINA_BASE: G:\Yuntu\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: CATALINA_HOME: G:\Yuntu\apache-tomcat-8.0.42
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Command line argument: -Dcatalina.base=G:\Yuntu\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Command line argument: -Dcatalina.home=G:\Yuntu\apache-tomcat-8.0.42
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Command line argument: -Dwtp.deploy=G:\Yuntu\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Command line argument: -Djava.endorsed.dirs=G:\Yuntu\apache-tomcat-8.0.42\endorsed
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.VersionLoggerListener log
      信息: Command line argument: -Dfile.encoding=GBK
      三月 28, 2017 4:17:44 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
      信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_112\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_121/bin/server;C:/Program Files/Java/jre1.8.0_121/bin;C:/Program Files/Java/jre1.8.0_121/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\C:\Program Files\Java\jdk1.8.0_112\bin;C:\Program Files\Java\jdk1.8.0_112\bin;C:\Program Files\MySQL\MySQL Utilities 1.6;G:\JAVA_WEB\apache-maven-3.3.9\bin;G:\Yuntu\eclipse;;.
      三月 28, 2017 4:17:44 下午 org.apache.coyote.AbstractProtocol init
      信息: Initializing ProtocolHandler ["http-nio-8080"]
      三月 28, 2017 4:17:44 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
      信息: Using a shared selector for servlet write/read
      三月 28, 2017 4:17:44 下午 org.apache.coyote.AbstractProtocol init
      信息: Initializing ProtocolHandler ["ajp-nio-8009"]
      三月 28, 2017 4:17:44 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
      信息: Using a shared selector for servlet write/read
      三月 28, 2017 4:17:44 下午 org.apache.catalina.startup.Catalina load
      信息: Initialization processed in 1320 ms
      三月 28, 2017 4:17:44 下午 org.apache.catalina.core.StandardService startInternal
      信息: Starting service Catalina
      三月 28, 2017 4:17:44 下午 org.apache.catalina.core.StandardEngine startInternal
      信息: Starting Servlet Engine: Apache Tomcat/8.0.42
      三月 28, 2017 4:17:45 下午 org.apache.catalina.core.ContainerBase startInternal
      严重: A child container failed during start
      java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/FreemarkerTest3]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:192)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
      Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/FreemarkerTest3]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
      ... 6 more
      Caused by: java.lang.NoClassDefFoundError: freemarker/template/TemplateException
      at java.lang.Class.getDeclaredFields0(Native Method)
      at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
      at java.lang.Class.getDeclaredFields(Class.java:1916)
      at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
      at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256)
      at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:132)
      at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
      at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:336)
      at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:786)
      at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:307)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5213)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
      ... 6 more
      Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
      ... 20 more
      三月 28, 2017 4:17:45 下午 org.apache.catalina.core.ContainerBase startInternal


      3楼2017-03-28 16:21
      回复
        严重: A child container failed during start
        java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
        Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        Caused by: org.apache.catalina.LifecycleException: A child container failed during start
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        ... 6 more
        三月 28, 2017 4:17:45 下午 org.apache.catalina.startup.Catalina start
        严重: The required Server component failed to start so Tomcat is unable to start.
        org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
        Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        ... 7 more
        Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        ... 9 more
        Caused by: org.apache.catalina.LifecycleException: A child container failed during start
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        ... 11 more
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol pause
        信息: Pausing ProtocolHandler ["http-nio-8080"]
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol pause
        信息: Pausing ProtocolHandler ["ajp-nio-8009"]
        三月 28, 2017 4:17:45 下午 org.apache.catalina.core.StandardService stopInternal
        信息: Stopping service Catalina
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol destroy
        信息: Destroying ProtocolHandler ["http-nio-8080"]
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol destroy
        严重: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
        java.lang.NullPointerException
        at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:315)
        at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:491)
        at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:883)
        at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
        at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:879)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol destroy
        信息: Destroying ProtocolHandler ["ajp-nio-8009"]
        三月 28, 2017 4:17:45 下午 org.apache.coyote.AbstractProtocol destroy
        严重: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
        java.lang.NullPointerException
        at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:315)
        at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:491)
        at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:883)
        at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
        at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:879)
        at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)


        4楼2017-03-28 16:24
        回复
          package com.yuntu.test.servlet;
          import java.io.IOException;
          import java.io.Writer;
          import java.util.HashMap;
          import java.util.Map;
          import javax.servlet.ServletException;
          import javax.servlet.annotation.WebServlet;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          import freemarker.template.Configuration;
          import freemarker.template.Template;
          import freemarker.template.TemplateException;
          /**
          * Servlet implementation class HelloFreeMarkSerlet
          */
          @WebServlet("/HelloFreeMarkSerlet")
          @SuppressWarnings("serial")
          public class HelloFreeMarkerServlet extends HttpServlet {
          Configuration cfg = null;
          public void init() throws ServletException{
          cfg = new Configuration();
          cfg.setServletContextForTemplateLoading(getServletContext(),
          "/WEB-INF/tamplates");
          }
          @SuppressWarnings("unchecked")
          protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
          Map root = new HashMap();
          root.put("message", "hello world");
          root.put("nmae", "迷失");
          Template t = cfg.getTemplate("test.ftl");
          response.setContentType("text/html;charset=" + t.getEncoding());
          Writer out = response.getWriter();
          try {
          t.process(root, out);
          } catch (TemplateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          }
          }
          /**
          * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
          */
          @SuppressWarnings("unchecked")
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          doPost(request, response);
          }
          public void destroy(){
          super.destroy();
          }
          }


          5楼2017-03-28 16:24
          回复
            <html>
            <head>
            <title>freemarker测试</title>
            </head>
            <body>
            <h1>${message},${name}</h1>
            </body>
            </html>


            6楼2017-03-28 16:25
            回复
              <?xml version="1.0" encoding="UTF-8"?>
              <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
              <display-name>FreemarkerTest3</display-name>
              <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>
              <welcome-file>default.html</welcome-file>
              <welcome-file>default.htm</welcome-file>
              <welcome-file>default.jsp</welcome-file>
              </welcome-file-list>
              </web-app>


              7楼2017-03-28 16:25
              回复
                <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="utf-8"%>
                <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                <%
                String path = request.getContextPath();
                String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
                %>
                <html>
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                <title>Insert title here</title>
                </head>
                <body>
                <%
                String mypath = "hello";
                response.sendRedirect(basePath + mypath);
                %>
                </body>
                </html>


                8楼2017-03-28 16:25
                回复


                  9楼2017-03-28 16:26
                  回复