java 使用Tomcat手动部署webapp(即autoDeploy=false,noDeployOnStartup=false)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13278123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:05:58  来源:igfitidea点击:

Deploy webapp manually with Tomcat (ie autoDeploy=false, noDeployOnStartup=false)

javajakarta-eetomcat

提问by chubbsondubs

I'm trying to deploy several web applications to tomcat 6.x, and I've turned off autoDeploy and onDeployStartup because I want to manually register these apps and map them to URLs not based on the names of their war files.

我正在尝试将多个 Web 应用程序部署到 tomcat 6.x,并且我已经关闭了 autoDeploy 和 onDeployStartup,因为我想手动注册这些应用程序并将它们映射到不基于其War文件名称的 URL。

I've put the following context file in $catalina.home/conf/Catalina/localhost:

我已将以下上下文文件放在 $catalina.home/conf/Catalina/localhost 中:

<Context path="" docBase="web-1.0-SNAPSHOT.war" debug="1">
</Context>

And I put the war file under $catalina.home/webapps, but when I startup tomcat nothing gets deployed. I don't even see any error messages about the context files I created. Or any print outs saying anything is wrong.

我将 war 文件放在 $catalina.home/webapps 下,但是当我启动 tomcat 时,什么也没有部署。我什至没有看到有关我创建的上下文文件的任何错误消息。或者任何打印出来的东西都说错了。

What's the problem? I've read the documents which outlines autodeploy a lot, but is very sketchy on details of how to do this outside of autodeploy.

有什么问题?我已经阅读了很多概述 autodeploy 的文档,但对如何在 autodeploy 之外执行此操作的细节非常粗略。

采纳答案by chubbsondubs

So the details about how autoDeploy works, and alternative deployments is only really discussed here.:

所以关于 autoDeploy 如何工作的细节和替代部署只在这里真正讨论。:

http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application.3F

http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application.3F

I don't know why tomcat makes this so complicated. If you turn off autoDeploy your only option is to modify the server.xml and add your contexts there. You can't externalize the definitions of your contexts which seems convoluted way to deploy things. If I'm going to take the time to drop a XML config file I should be able to control the URL it's mounted to and the docBase. Just make it straight forward because Jetty does.

我不知道为什么 tomcat 把这弄得这么复杂。如果您关闭 autoDeploy,您唯一的选择就是修改 server.xml 并在那里添加您的上下文。您无法将上下文的定义外部化,这似乎是部署事物的复杂方式。如果我要花时间删除 XML 配置文件,我应该能够控制它挂载到的 URL 和 docBase。直截了当,因为 Jetty 做到了。

回答by Konza

Try the following steps

尝试以下步骤

Shutdown the tomcat

关闭tomcat

Copy web-1.0-SNAPSHOT.war to webapps folder.

将 web-1.0-SNAPSHOT.war 复制到 webapps 文件夹。

Deploy the webapp.

部署 web 应用程序。

Now there is a folder named web-1.0-SNAPSHOT inside webapps.

现在在 webapps 中有一个名为 web-1.0-SNAPSHOT 的文件夹。

go to conf/server.xml

去 conf/server.xml

Add the following entries

添加以下条目

<Context path="/abc" docBase="web-1.0-SNAPSHOT" debug="1"></Context>

The docbase doesn't have the .war extention. When web-1.0-SNAPSHOT.war is deployed there will be a directory web-1.0-SNAPSHOT inside webapps. The docbase should point to this directory.

文档库没有 .war 扩展名。部署 web-1.0-SNAPSHOT.war 后,webapps 中将有一个目录 web-1.0-SNAPSHOT。文档库应该指向这个目录。

Please make sure that Context tag is within the

请确保 Context 标签在

<Host>  </Host> tag 

<Host>
    <Context path="/abc" docBase="web-1.0-SNAPSHOT" debug="1"></Context>
</Host>

After editing server.xml you have to restart tomcat server to reflect the changes. Now you can find your webapp at

编辑 server.xml 后,您必须重新启动 tomcat 服务器以反映更改。现在您可以在以下位置找到您的网络应用程序

localhost:8080/abc

Hope this helps

希望这可以帮助

回答by Doesystem

Example code

示例代码

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false" deployOnStartup="false">


    <Context path="/howto-prepareexam" docBase="howto-prepareexam" debug="1"></Context>

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

Then restart tomcat

然后重启tomcat

回答by Doesystem

Setting deployonstartup to false tells tomcat not to deploy apps on startup. I think its enough to turn autodeploy off. so maybe try the following in the Host in server.xml: autoDeploy="false" deployOnStartup="true".

将 deployonstartup 设置为 false 会告诉 tomcat 在启动时不要部署应用程序。我认为关闭自动部署就足够了。所以也许可以在 server.xml 中的主机中尝试以下操作:autoDeploy="false" deployOnStartup="true"。