[英]How can I deploy war in Tomcat 6
I have used Jboss and deployment happens by dropping war to deploy folder. 我使用了Jboss并通过将war放到deploy文件夹来进行部署。 But when I set my war project to Tomcat server eclipse claims that it is deploying war, but I cannot see my war in webapps folder. 但是当我将我的战争项目设置为Tomcat服务器时,eclipse声称它正在部署战争,但我无法在webapps文件夹中看到我的战争。 And what url is to my war? 我的战争是什么网址? In jboss I can add app url to jboss-web.xml, so when I set app path to jboss-web.xml I can find my app from http://localhost:8080/my_app_path_in_jboss_web.xml/ . 在jboss中我可以将应用程序URL添加到jboss-web.xml,所以当我将应用程序路径设置为jboss-web.xml时,我可以从http:// localhost:8080 / my_app_path_in_jboss_web.xml /找到我的应用程序。
I deploy WARs to the webapps dir all the time without issue, probably ~25 times a day. 我总是将WAR部署到webapps dir而没有问题,可能每天约25次。 You shouldn't have any problems with that. 你不应该有任何问题。 If you want more control by all means deploy the directory yourself, but this will most likely require a restart. 如果您希望通过各种方式进行更多控制,请自行部署目录,但这很可能需要重新启动。
Using ant simplifies the task. 使用ant简化了任务。 Here is an an ant build.xml file I use to deploy to tomcat 6. (note, I wasn't the origial author of this, but I forget where I got it from) 这是一个用于部署到tomcat 6的ant build.xml文件。(注意,我不是这个的原始作者,但我忘记了从哪里得到它)
<project name="provisioning" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="provisioning"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}"/>
</target>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
If I understand correctly, you have configured eclipse to use Tomcat by adding a new Server. 如果我理解正确,您已通过添加新服务器将eclipse配置为使用Tomcat。 In that case eclipse deploys the war file in folder inside your workspace, NOT at $TOMCAT_HOME/webapps. 在这种情况下,eclipse将war文件部署在工作区内的文件夹中,而不是$ TOMCAT_HOME / webapps。 I can't remember the path in eclipse's workspace folder from the top of my head - it should be something that contains tmp, server, ... 我不记得eclipse的工作区文件夹中的路径从头顶 - 它应该是包含tmp,server,...的东西
You have added Tomcat server in eclipse, eclipse runs the WAR file within your workspace. 您已在eclipse中添加了Tomcat服务器,eclipse在您的工作区中运行WAR文件。 Eclipse does not use your %TOMCAT_HOME%. Eclipse不使用%TOMCAT_HOME%。 To be able to see your WAR in the webapps folder simply drop it in there. 为了能够在webapps文件夹中查看您的WAR,只需将其放入其中即可。 You will then be albe to run the war from localhost. 然后你将从localhost运行战争。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.