java - tomcat 启动失败 : SEVERE: Error starting static Resources

标签 java tomcat

我已经通读了所有现有的答案,但仍然无法解决我的问题。

  1. 我有一个嵌入式 tomcat 实例,它曾经工作很好
  2. 我什至创建了一个全新的安装,但它仍然在 同理
  3. 我重新启动了我的机器;模糊地希望那会 帮助。它没。
  4. 我不擅长配置(我正在 不过更好……)

我如何启动服务器:

alias run-server='cd /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery/; java -Dgcs.log.dir=/Users/usingji/mediaServer/log -Dgcs.home.dir=/Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery -jar GCS-v0.9.jar'

我的错误:

   0:36:45,083 INFO  [PropertyUtil] Loading Property file
10:36:45,084 INFO  [PropertyUtil] Loading Property file
10:36:45,085 INFO  [ServerLauncher] webPort is 8080
10:36:45,085 INFO  [ServerLauncher] web root is webapp 
10:36:45,091 INFO  [ServerLauncher] base path: /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery
10:36:45,092 INFO  [ServerLauncher] just set the port
10:36:45,092 INFO  [ServerLauncher] config name: webapp 
10:36:45,092 INFO  [ServerLauncher] file: ackack: /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery/webapp 
10:36:45,092 INFO  [ServerLauncher] absolute path: /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery/webapp 
10:36:45,175 INFO  [ServerLauncher] configuring app with basedir: /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery/webapp 
Jan 22, 2014 10:36:45 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 22, 2014 10:36:45 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jan 22, 2014 10:36:45 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.34
Jan 22, 2014 10:36:45 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Jan 22, 2014 10:36:46 AM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /Users/usingji/Code/sandbox/gcs/target/GlobalContentDelivery-Package/GlobalContentDelivery/webapp  does not exist or is not a readable directory
    at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:138)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4906)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5086)
    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(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

Jan 22, 2014 10:36:46 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Jan 22, 2014 10:36:46 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Jan 22, 2014 10:36:46 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/] startup failed due to previous errors
Jan 22, 2014 10:36:46 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
10:36:46,227 INFO  [ServerLauncher] Starting Tomcast ...

webapp 目录确实存在:

drwxr-xr-x   6 usingji  PEROOT\Domain Users    204 Jan 22 10:34 webapp

启动tomcat实例的代码:

 public static void main(String[] args) throws Exception {

        // load all the default configs files
        loadDefaults();

        // // port number
        String webPort;
        webPort = System.getProperty("gcs.web.port");
        if (webPort == null) {
            webPort = System.getenv("gcs.web.port");
        }
        if (webPort == null) {
            webPort = PropertyUtil.getValue(Constants.PORT_CONFIG_NAME);
        }
        log.info("webPort is " + webPort);
        String webappDirLocation = PropertyUtil.getValue(Constants.WEBAPP_CONFIG_NAME);
        log.info("web root is " + webappDirLocation);
        tomcat = new Tomcat();
        String basePath = FileUtil.getBasePath();
        log.info("base path: " + basePath);
        tomcat.setBaseDir(basePath);
        tomcat.setPort(Integer.valueOf(webPort));
        log.info("just set the port");

        String configName= PropertyUtil.getValue(Constants.WEBAPP_CONFIG_NAME);
        log.info("config name: "+ configName);
        File ackack = new File(basePath,configName);
        log.info("file: ackack: " + ackack);
       String absPath  = ackack.getAbsolutePath();
       log.info("absolute path: " + absPath);
        StandardContext ctx = (StandardContext) tomcat.addWebapp(
                "/",
                absPath);
        ctx.setDefaultWebXml(new File(webappDirLocation).getAbsolutePath()
                + "/WEB-INF/web.xml");

        // unzip folder location
        tomcat.addWebapp(PropertyUtil.getValue(Constants.EXPORT_URL_PATH),
                PropertyUtil.getValue(Constants.PXE_UNZIP_FOLDER));

        log.info("configuring app with basedir: "
                + new File(webappDirLocation).getAbsolutePath());

        tomcat.start();
        log.info("Starting Tomcast ...");
        tomcat.getServer().await();
    }

最佳答案

事实证明,具有文件夹 (webapp) 链接的配置文件在文件名后有一个空格或一个不可见的控制字符。

我通过以下方式发现了这一点:

  1. 恢复到工作代码的早期版本
  2. 我的同事 提到他们有同样的问题并且修复了配置 文件修复了它
  3. 然后我比较了非工作配置文件和工作文件并发现了问题

如此令人沮丧和阴险!我很高兴现在已经解决并完成了!

关于java - tomcat 启动失败 : SEVERE: Error starting static Resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287440/

相关文章:

java - 在 JSON 上使用 #text 以使用 Json.org 在 XML 上进行转换

java - 模式匹配通过排除最后一个来提取大括号

java - 如何在 SOLR (mini) 中存储关系数据

html - 如何在 Ubuntu 的 Tomcat 7 上启用 SSI(服务器端包含)?

xml - 在 JSP 文件中导入带有 JSTL 核心的 XML 文件时,请求的资源不可用

java - LD_PRELOAD 套接字函数 java

java - Swagger 引用对 Spring 对象的响应,使用 Swagger 进行分页

java - 如何将给定时间(如日期字符串)转换为 13 位时间戳

tomcat - 如何在 servlet 容器中部署 Solr 和前端 Web 应用程序配置

java - 名称 [资源] 未在此上下文中绑定(bind)。找不到 [jdbc]