问题描述
我一直在关注非常好的 Tomcat6 应用程序开发人员指南.我抓住了他们的 build.xml
,其中包含名为 install
的方便的 ant 任务,它使用 catalina-ant.jar
任务 deploy代码>.
I've been following along the very good Tomcat6 Application Developers Guide. I've grabbed their build.xml
which contains the handy ant task called install
that uses the catalina-ant.jar
task deploy
.
<target name="install" depends="compile"
description="Install application to servlet container">
<deploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="${app.path}"
localWar="file://${build.home}"/>
</target>
我的项目目前位于 /home/leif/test/mytomcatapp/
.
我的 build.properties
看起来像:
manager.username=admin
manager.password=admin
manager.url=http://localhost:8080/manager/
cataline.home=/usr/share/tomcat6/
我的 /etc/tomcat6/tomcat-users.xml
看起来像:
<role rolename="admin"/>
<role rolename="manager"/>
<user name="admin" password="admin" roles="admin,manager" />
但是,当我执行 ant install
来测试我的 web 应用程序时,我在部署它时遇到错误:
But, when I do my ant install
to test out my webapp I get an error deploying it:
$ ant install
Buildfile: build.xml
Trying to override old definition of datatype resources
prepare:
compile:
install:
[deploy] FAIL - Failed to deploy application at context path /mytomcatapp
BUILD FAILED
FAIL - Failed to deploy application at context path /mytomcatapp
在 /var/log/tomcat/catalina.out
中它说:
java.io.FileNotFoundException: /home/leif/test/mytomcatapp/build (Permission denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:137)
at org.apache.catalina.manager.ManagerServlet.copyInternal(ManagerServlet.java:1644)
at org.apache.catalina.manager.ManagerServlet.copy(ManagerServlet.java:1605)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:819)
at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:636)
因此 Tomcat 管理器无法访问我的主目录中的文件.没有什么令人震惊的.但是 ant install
任务是如何工作的呢?这当然是假设人们将项目的源代码保存在他们的主目录中,并从该位置执行 ant install
.我宁愿不打开我家目录的权限,一定有更好的方法吗?
So Tomcat manager can't access the files in my home dir. Nothing shocking there. But how is the ant install
task ever expected to work? This is of course presuming people keep the source code for their project in their home dir and excute ant install
from that location. I'd rather not crank open the permissions on my home dir, there must be a better way?
推荐答案
你需要把你的 webapp 打包成一个 .war 文件,然后让 ant 把它上传到 Tomcat.如果您使用示例 build.xml ,只需让安装目标依赖于 dist
目标,并更改
You need package up your webapp in a .war file, and have ant upload it to Tomcat. If you're using the sample build.xml , just have the install target depend on the dist
target, and change
localWar="file://${build.home}"
到
war="${dist.home}/${app.name}-${app.version}.war"`
或者,更改您的 build.xml 以将战争输出到您可以与 tomcat 共享的目录 - 例如/tmp 下的某处
Alternativly, change your build.xml to output the war to a directory that you can share with tomcat - e.g. somewhere under /tmp
这篇关于ant install 部署Tomcat webapp失败,权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!