nguyenngoc101
nguyenngoc101

Reputation: 1211

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

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

chmod -R 777 /opt/mywebapps/

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.

Upvotes: 1

Views: 11913

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48057

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

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

Note that you now have /opt/mywebapps/FooBar.war, while you're referencing /opt/mywebapps/FooBar. (note the difference in ".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.

Upvotes: 2

Related Questions