如何在 Tomcat 8 中设置上下文路径 [英] How to set context path in Tomcat 8

查看:48
本文介绍了如何在 Tomcat 8 中设置上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 FooBar.war 的 war 文件,现在我想设置上下文路径/"指向这个网络应用程序.这意味着用户可以通过 URL 访问 webapp:localhost:8080/为此,我在 <catalina_home>/conf/Catalina/localhost/ with content

I have a war file named FooBar.war, now I want to set context path "/" point to this web apps. It means Users can access the webapp via URL: localhost:8080/ To do that I add a file called ROOT.xml in <catalina_home>/conf/Catalina/localhost/with content

<Context docBase="/opt/mywebapps/FooBar" path="" reloadable="true" />

我也把 FooBar.war 放入文件夹 /opt/mywebapps/然后设置此文件夹的所有权限:

And I also put FooBar.war into folder /opt/mywebapps/ then set all permissions for this folder:

chmod -R 777 /opt/mywebapps/

启动Tomcat服务器后,服务器无法部署war文件:

After starting Tomcat server, the server can not deploy the war file:

1-Apr-2019 11:33:36.211 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@6023aae1]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4932)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5067)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [/opt/mywebapps/FooBar] is not valid
    at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:748)
    at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:706)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 13 more

如果您有任何想法可以解决它,请帮助我.

If you have any ideas to fix it, please help me.

推荐答案

<Context docBase="/opt/mywebapps/FooBar" path="" reloadable="true" />

我也将 FooBar.war 放入文件夹/opt/mywebapps/

And I also put FooBar.war into folder /opt/mywebapps/

请注意,您现在拥有 /opt/mywebapps/FooBar.war,而您正在引用 /opt/mywebapps/FooBar.(注意.war"的区别)

Note that you now have /opt/mywebapps/FooBar.war, while you're referencing /opt/mywebapps/FooBar. (note the difference in ".war")

由于您不在 Tomcat 自己的 webapps 文件夹中,其中(使用默认配置)WAR 文件将自动解压缩,Tomcat 只是表示您配置的位置根本不存在.

As you're not in Tomcat's own webapps folder, where (with the default configuration) WAR files will be automatically unzipped, Tomcat just signals that the location that you've configured simply doesn't exist.

这篇关于如何在 Tomcat 8 中设置上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆