简体   繁体   English

如何在Tomcat 8中设置上下文路径

[英]How to set context path in Tomcat 8

I have a war file named FooBar.war , now I want to set context path "/" point to this web apps. 我有一个名为FooBar.war的战争文件,现在我想将上下文路径“ /”指向该Web应用程序。 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 这意味着用户可以通过URL访问Webapp: localhost:8080/为此,我在<catalina_home>/conf/Catalina/localhost/添加了一个名为ROOT.xml的文件,其中包含内容

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

And I also put FooBar.war into folder /opt/mywebapps/ then set all permissions for this folder: 我还将FooBar.war放到/opt/mywebapps/文件夹中,然后设置此文件夹的所有权限:

chmod -R 777 /opt/mywebapps/

After starting Tomcat server, the server can not deploy the war file: 启动Tomcat服务器后,该服务器无法部署war文件:

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" /> 

And I also put FooBar.war into folder /opt/mywebapps/ 而且我还将FooBar.war放到/ opt / mywebapps /文件夹中

Note that you now have /opt/mywebapps/FooBar.war , while you're referencing /opt/mywebapps/FooBar . 请注意,您现在有/opt/mywebapps/FooBar.war ,当你引用/opt/mywebapps/FooBar (note the difference in ".war") (请注意“ .war”中的区别)

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自己的webapps文件夹中,该文件夹(具有默认配置)将自动解压缩WAR文件,因此Tomcat只是表示您所配置的位置根本不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM