如何在 tomcat 上部署 Java Web 应用程序 (.war)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2217693/
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
How to deploy a Java Web Application (.war) on tomcat?
提问by Yatendra Goel
I have a .war
file of a Java Web Application. Now I want to upload it to my ftp server so that I can execute it.
我有一个.war
Java Web 应用程序的文件。现在我想将它上传到我的 ftp 服务器,以便我可以执行它。
What steps I should perform to run it?
我应该执行哪些步骤来运行它?
The context path of the webapp is /mywebapp
webapp 的上下文路径是 /mywebapp
Edit
编辑
Actually, my ftp server name is ftp://bilgin.ath.cx/and I have uploaded my TestWebApp.warfile to this dir: ftp://bilgin.ath.cx/web
实际上,我的 ftp 服务器名称是ftp://bilgin.ath.cx/并且我已将我的TestWebApp.war文件上传到此目录:ftp: //bilgin.ath.cx/web
Then what should be the URL to access the index.htmlpage of the webapplication
那么访问webapplication的index.html页面的URL应该是什么
#2 Edit
#2 编辑
Tomcat
is listening on 8082
Tomcat
正在听 8082
Apache access Tomcat with jk connector.
Apache 使用 jk 连接器访问 Tomcat。
采纳答案by Pascal Thivent
As others pointed out, the most straightforward way to deploy a WAR is to copy it to the webapps
of the Tomcat install. Another option would be to use the manager application ifit is installed (this is not always the case), ifit's properly configured (i.e. if you have the credentials of a user assigned to the appropriate group) and ifit you can access it over an insecure network like Internet (but this is very unlikely and you didn't mention any VPN access). So this leaves you with the webapp
directory.
正如其他人指出的那样,部署 WAR 最直接的方法是将其复制到webapps
Tomcat 安装的目录中。另一种选择是使用管理器应用程序,如果它已安装(情况并非总是如此),如果它配置正确(即,如果您拥有分配给适当组的用户凭据),并且您可以访问它像 Internet 这样不安全的网络(但这不太可能,而且您没有提到任何 VPN 访问)。所以这给你留下了webapp
目录。
Now, if Tomcat is installed and running on bilgin.ath.cx
(as this is the machine where you uploaded the files), I noticed that Apache is listening to port 80
on that machien so I would bet that Tomcat is not directly exposed and that requests have to go through Apache. In that case, I think that deploying a new webapp and making it visible to the Internet will involve the edit of Apache configuration files (mod_jk
?, mod_proxy
?). You should either give us more details or discuss this with your hosting provider.
现在,如果 Tomcat 已安装并运行bilgin.ath.cx
(因为这是您上传文件的机器),我注意到 Apache 正在侦听该机器上的端口80
,所以我敢打赌 Tomcat 没有直接暴露,并且请求必须通过阿帕奇。在那种情况下,我认为部署一个新的 webapp 并使其对 Internet 可见将涉及编辑 Apache 配置文件(mod_jk
?,mod_proxy
?)。您应该向我们提供更多详细信息或与您的托管服务提供商讨论。
Update:As expected, the bilgin.ath.cx
is using Apache Tomcat + Apache HTTPD + mod_jk. The configuration usually involves two files: the worker.properties
file to configure the workers and the httpd.conf
for Apache. Now, without seeing the current configuration, it's not easy to give a definitive answer but, basically, you may have to add a JkMount
directive in Apache httpd.conf
for your new webapp1. Refer to the mod_jkdocumentation, it has a simple configuration example. Note that modifying httpd.conf
will require access to (obviously) and proper rights and that you'll have to restart Apache after the modifications.
更新:正如预期的那样,bilgin.ath.cx
正在使用 Apache Tomcat + Apache HTTPD + mod_jk。配置通常涉及两个文件:worker.properties
用于配置工作程序的文件和httpd.conf
用于 Apache 的文件。现在,在没有看到当前配置的情况下,要给出明确的答案并不容易,但基本上,您可能必须JkMount
在 Apache 中httpd.conf
为新的 webapp 1添加指令。请参阅mod_jk文档,它有一个简单的配置示例。请注意,修改httpd.conf
将需要访问(显然)和适当的权限,并且您必须在修改后重新启动 Apache。
1I don't think you'll need to define a new worker if you are deploying to an already used Tomcat instance, especially if this sounds like Chinese for you :)
1如果您要部署到已经使用过的 Tomcat 实例,我认为您不需要定义新的工作器,尤其是如果这对您来说听起来像中文:)
回答by tangens
The tomcat manualsays:
在Tomcat的手册说:
Copy the web application archive file into directory $CATALINA_HOME/webapps/. When Tomcat is started, it will automatically expand the web application archive file into its unpacked form, and execute the application that way.
将 Web 应用程序存档文件复制到 $CATALINA_HOME/webapps/ 目录中。当 Tomcat 启动时,它会自动将 Web 应用程序归档文件展开为解压后的形式,并以这种方式执行应用程序。
回答by Brian Agnew
Note that you can deploy remotely using HTTP.
请注意,您可以使用 HTTP 进行远程部署。
http://localhost:8080/manager/deploy
Upload the web application archive (WAR) file that is specified as the request data in this HTTP PUT request, install it into the appBase directory of our corresponding virtual host, and start it using the war file name without the .war extension as the path. The application can later be undeployed (and the corresponding application directory removed) by use of the /undeploy. To deploy the ROOT web application (the application with a context path of "/"), name the war ROOT.war.
http://localhost:8080/manager/deploy
上传本次HTTP PUT请求中指定为请求数据的Web应用归档(WAR)文件,安装到我们对应虚拟主机的appBase目录下,以不带.war扩展名的war文件名作为路径启动. 稍后可以使用 /undeploy 取消部署应用程序(并删除相应的应用程序目录)。要部署 ROOT Web 应用程序(上下文路径为“/”的应用程序),请将 war 命名为 ROOT.war。
and if you're using Ant you can do this using Tomcat Ant tasks(perhaps following a successful build).
如果您使用 Ant,则可以使用Tomcat Ant 任务(可能在成功构建之后)执行此操作。
To determine which path you then hit on your browser, you need to know the port Tomcat is running on, the context and your servlet path. See here for more details.
要确定您随后在浏览器上访问的路径,您需要知道 Tomcat 正在运行的端口、上下文和您的 servlet 路径。请参阅此处了解更多详情。
回答by Bozho
- copy the .war file in the
webapps
folder - upload the file using the manager application -
http://host:port/manager
. You will have to setup some users beforehand. - (not recommended, but working) - manually extract the .war file as a .zip archive and place the extracted files in
webapps/webappname
- 复制文件
webapps
夹中的 .war 文件 - 使用管理器应用程序上传文件 -
http://host:port/manager
. 您必须事先设置一些用户。 - (不推荐,但有效) - 手动将 .war 文件提取为 .zip 存档并将提取的文件放入
webapps/webappname
Sometimes administrators configure tomcat so that war files are deployed outside the tomcat folder. Even in that case:
有时管理员会配置 tomcat,以便将 war 文件部署在 tomcat 文件夹之外。即使在这种情况下:
After you have it deployed (check the /logs
dir for any problems), it should be accessible via: http://host:port/yourwebappname/
. So in your case, one of those:
部署后(检查/logs
目录是否有任何问题),它应该可以通过以下方式访问:http://host:port/yourwebappname/
。所以在你的情况下,其中之一:
http://bilgin.ath.cx/TestWebApp/
http://bilgin.ath.cx:8080/TestWebApp/
If you don't manage by doing the above and googling - turn to your support. There might be an alternative port, or there might be something wrong with the application (and therefore in the logs)
如果您不能通过执行上述操作和谷歌搜索来管理 - 转向您的支持。可能有一个替代端口,或者应用程序可能有问题(因此在日志中)
回答by rizwan
Log in :URL = "localhost:8080/" Enter username and pass word Click Manager App Scroll Down and find "WAR file to deploy" Chose file and click deploy
登录 :URL = "localhost:8080/" 输入用户名和密码 点击 Manager App 向下滚动,找到“要部署的 WAR 文件” 选择文件并点击部署
Done
完毕
Go to Webapp folder of you Apache tomcat you will see a folder name matching with your war file name.
转到 Apache tomcat 的 Webapp 文件夹,您将看到与您的 war 文件名匹配的文件夹名称。
Type link in your url address bar:: localhost:8080/HelloWorld/HelloWorld.html and press enter
在你的 url 地址栏中输入 link::localhost:8080/HelloWorld/HelloWorld.html 然后按回车
Done
完毕