2011-08-13 14 views
1

私のbuild.xmlジャワ、春、Antは2つのwarファイルを展開

<?xml version="1.0"?> 

<project name="spring" 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="project"/> 

    <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.5" target="1.5" debug="true" 
       deprecation="false" optimize="false" failonerror="true" includeantruntime="false"> 
      <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> 

    <target name="clean" description="Clean output directories"> 
     <delete> 
      <fileset dir="${build.dir}"> 
       <include name="**/*.class"/> 
      </fileset> 
     </delete> 
    </target> 

<!-- ============================================================== --> 
<!-- Tomcat tasks - remove these if you don't have Tomcat installed --> 
<!-- ============================================================== --> 

    <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.DeployTask"> 
     <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> 

<!-- End Tomcat tasks --> 

</project> 

build.properties:

# Ant properties for building the springapp 

appserver.home=C:/apache-tomcat-7.0.20 
# for Tomcat 5 use $appserver.home}/server/lib 
# for Tomcat 6 use $appserver.home}/lib 
appserver.lib=C:/apache-tomcat-7.0.20/lib 

deploy.path=C:/apache-tomcat-7.0.20/webapps 

tomcat.manager.url=http://localhost:8080/manager 
tomcat.manager.username=tomcat 
tomcat.manager.password=s3cret 

enter image description here enter image description here

私はdeploywar後、2つのwarファイルが表示されます。そして、それらを削除しても、常に同じ日付が変更されます。

project.warは本当のものですが、問題は、なぜ他の戦争が来るのですか?

答えて

1

に古いビルドからちょうど残り物$ {名前} .warのではないですか?プロジェクトディレクトリから削除するだけで、元に戻りません。

+0

ええ、問題は、私は積極的に削除し、日食でファイルを追加しています。 1つは、Eclipseのワークスペースからファイルを削除することです。もう1つは、それは私のプロジェクトのDIRに残っていて、FKのものを残します! hehe、それは働いた – Jaanus

+0

私はあなたがここにいると思う@Jaanusあなたはおそらくあなたのビルドターゲットをきれいに依存する必要がありますので、常に素敵なクリーンなビルドを取得する必要があります – eon

2

ここにあなたのケースを作成するための詳細がありません。これを試してbulid.propertiesしかし:あなたのdeploywarターゲットの変更

<include name="*.war"/> to 

<include name="${name}.war"/> 
+0

ビルドプロパティを追加しましたが、提案した内容を試してみてください。私はそれが働いたと思う! – Jaanus

+0

作業領域のwarディレクトリに2つのwarファイルがあります。だからあなたは、あなたが必要とするただ1つのwarファイルをコピーするように頼んだ。 – zawhtut

関連する問題