本文介绍了使用自定义上下文 XML 时如何使用 URL API 部署 Tomcat 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序上下文定义为位于 my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml 中的 XML 文件.

My application context is defined as an XML file located in my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml.

<Context docBase='/my/path/to/myApp/myAppWarFile.war'>
   <Environment name='my_config_dir' value='/my/path/to/myApp' type='java.lang.String'/>
</Context>

/my/path/to/myApp 包含 WAR 文件 myAppWarFile.war 和许多由 Spring 读取的外部属性.

/my/path/to/myApp contains the WAR file myAppWarFile.war and a number of externalized properties that are read by Spring.

Tomcat 配置为关闭了 autoDeploy.当我启动 Tomcat 时,它会创建 my/path/to/Tomcat/conf/webapps/my-app/ 并且 WAR 文件按预期解压到这个位置,应用程序当然可以作为预期.

Tomcat is configured with autoDeploy turned off. When I start Tomcat, it creates my/path/to/Tomcat/conf/webapps/my-app/ and the WAR file gets unpacked into this location as expected, and the application of course can run as expected.

当我想在不重启Tomcat的情况下部署新版本时,运行undeploy命令如下:

When I want to deploy a new version without restarting Tomcat, I run the undeploy command as follows:

curl http://localhost:8080/manager/text/undeploy?path=/my-app --user my-username:my-password

... 并且有效.但是,当我使用以下 curl 语句指示 Tomcat 部署时,却失败了.

... and that works. But when I instruct Tomcat to deploy with the following curl statement, I get a failure.

curl http://localhost:8080/manager/text/deploy?config=file:/my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml --user my-username:my-password
# Tomcat response
FAIL - Invalid context path null was specified

添加路径没有多大帮助,我还是失败了.

Adding the path does not help much, I still get a failure.

curl http://localhost:8080/manager/text/deploy?config=file:/my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml\&path=/my-app --user my-username:my-password

# Tomcat response
FAIL - Failed to deploy application at context path /my-app

最糟糕的是,跟踪 catalina.out 不会产生任何洞察力.最重要的是,Tomcat 删除了应用程序上下文 XML 文件 my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml!

The worst part is that tailing catalina.out does not yield any insight. And on top of that, Tomcat deletes the application context XML file my/path/to/Tomcat/conf/Catalina/localhost/my-app.xml!

当然我已经查看了 Tomcat 文档(https://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html#Deploy_using_a_Context_configuration_%22.xml%22_file) 我已经用谷歌搜索了一整天来弄清楚这一点,但我没有找到了任何可以帮助我完成此特定配置的事情.

Naturally I have reviewed Tomcat documentation (https://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html#Deploy_using_a_Context_configuration_%22.xml%22_file) and I have googled all day to figure this out, but I have not found anything that can help me with this particular configuration.

感觉好像选择是:

  1. 启用 autoDeploy 的 Tomcat(不推荐用于生产)在这种情况下,只需将新的 WAR 放到 /my/path/to/myApp/ 将导致 Tomcat 热部署应用程序.
  2. Tomcat 已关闭 autoDeploy,但重新部署需要重新启动 Tomcat,因为部署 API 似乎不像宣传的那样工作.
  1. Tomcat with autoDeploy on (not recommended for production) in which case simply dropping the new WAR to /my/path/to/myApp/ will cause Tomcat to hot deploy the app.
  2. Tomcat with autoDeploy off, but re-deploying requires a Tomcat restart because the deploy API does not seem to be working as advertised.

有人用这个配置完成这项工作吗?

Has anybody made this work with this configuration?

我打开了 Catalina 上的日志记录.当我在没有路径的情况下运行第一个部署命令时,我得到了这组日志条目:

I turned up the logging on Catalina. When I run the first deploy command without the path, I get this set of log entries:

FINE: Start processing with input [config=file:/my/apth/to/tomcat/conf/Catalina/localhost/my-app.xml]
Oct 13, 2015 10:04:53 AM org.apache.coyote.AbstractProtocol$AbstractConnectionHandler process
FINE: Socket: [org.apache.tomcat.util.net.SocketWrapper@189651c1:Socket[addr=/0:0:0:0:0:0:0:1,port=45415,localport=8080]], Status in: [OPEN_READ], State out: [OPEN]
Oct 13, 2015 10:04:53 AM org.apache.coyote.http11.AbstractHttp11Processor process
FINE: Error parsing HTTP request header
java.io.EOFException: Unexpected EOF read on the socket
    at org.apache.coyote.http11.Http11Processor.setRequestLineReadTimeout(Http11Processor.java:168)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:982)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:744)

Oct 13, 2015 10:04:53 AM org.apache.coyote.AbstractProtocol$AbstractConnectionHandler process
FINE: Socket: [org.apache.tomcat.util.net.SocketWrapper@189651c1:Socket[addr=/0:0:0:0:0:0:0:1,port=45415,localport=8080]], Status in: [OPEN_READ], State out: [CLOSED]
Oct 13, 2015 10:04:53 AM org.apache.tomcat.util.threads.LimitLatch countDown
FINE: Counting down[http-bio-8080-exec-16] latch=1

推荐答案

您是否尝试过:

curl --upload-file /my/path/to/my-app.war http://localhost:8080/manager/text/deploy?path=/my-app --user my-username:my-password

这篇关于使用自定义上下文 XML 时如何使用 URL API 部署 Tomcat 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:18