我一直在关注非常好的Tomcat6 Application Developers Guide。我抓住了他们的build.xml
,其中包含使用install
任务catalina-ant.jar
的名为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
测试我的网络应用程序时,我遇到错误部署它:
$ 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
。我宁愿不打开我家里的权限,必须有更好的方法吗?
答案 0 :(得分:2)
您需要在.war文件中打包您的webapp,并将其上传到Tomcat。如果您使用的是示例build.xml,请让安装目标取决于dist
目标,然后更改
localWar="file://${build.home}"
到
war="${dist.home}/${app.name}-${app.version}.war"`
另外,更改build.xml以将war输出到可以与tomcat共享的目录 - 例如某处/ tmp