2013-08-03 60 views
0

我有一個Java Web應用程序。我將這個作爲一個使用Ant文件的戰爭部署到Tomcat服務器上。我可以成功地做到這一點。請在下面找到build.xml 現在的挑戰是我有我的應用程序下的web文件夾中的100000圖像複製到戰爭根文件夾。如何在tomcat上部署戰爭時跳過圖像

如果我在war文件的根文件夾中創建了100000個圖像的戰爭,那將是很頭疼的事情。

每當我改變JSP或Java代碼中的任何東西,新的戰爭再次將這些100000圖像複製到戰爭文件夾,這需要超過1小時建立戰爭文件。

如何確保我的圖像文件夾在戰爭中不會一次又一次地被複制到每次部署?

<!-- setting classpath --> 


<path id="base.class.path"> 
    <pathelement location="lib/joda-time-1.6.1.jar" /> 
    <pathelement location="lib/fedExTrackingWebService.jar" /> 
    .... 
    ..... 
</path> 

<property file="build.properties"/> 

    <path id="classpath"> 
     <fileset dir="${lib.dir}"/> 
    </path> 

    <target name="clean"> 
     <echo>Cleaning the ${build.dir}</echo> 
     <delete dir="${build.dir}"/> 
     <delete dir="${dist.dir}"/> 
    </target> 

    <target name="init" depends="clean"> 
     <echo>Creating the build directory</echo> 
     <mkdir dir="${build.dir}/WEB-INF/classes"/> 
     <mkdir dir="${build.dir}/WEB-INF/lib"/> 
     <mkdir dir="${dist.dir}"/> 
    </target> 

    <target name="compile" depends="init"> 
     <echo>Compile the source files</echo> 
     <javac srcdir="${src.dir}" destdir="${build.dir}/WEB-INF/classes"> 
      <classpath refid="base.class.path"/>     
     </javac> 
    </target> 

    <target name="copy" depends="compile"> 
     <copy todir="${build.dir}/WEB-INF"> 
      <fileset dir="${web.dir.webinf}/WEB-INF"/> 
     </copy> 
     <copy todir="${build.dir}"> 
      <fileset dir="${web.dir}"/> 
     </copy> 
     <copy todir="${build.dir}/WEB-INF/lib"> 
      <fileset dir="${lib.dir}"> 
          </fileset> 
     </copy> 
    </target> 


    <target name="war"> 
     <echo>Building the war file</echo> 
     <war destfile="${dist.dir}/${ant.project.name}.war" webxml="${build.dir}/WEB-INF/web.xml"> 
      <fileset dir="${build.dir}"/> 
     </war> 
    </target> 

    <target name="deploy_local" depends="war"> 
     <echo>Deploying .war to local Tomcat</echo> 
     <copy todir="${tomcat.dir}/webapps"> 
      <fileset dir="${dist.dir}"> 
       <include name="${ant.project.name}.war"/> 
      </fileset> 
     </copy> 
    </target> 

+0

請問您能更具體嗎?你如何創建戰爭文件? maven戰爭插件,螞蟻戰爭任務,jar -cf等? – lifus

+0

它的螞蟻戰爭任務 - 請在構建文件上方找到。我正在部署使用螞蟻的戰爭。 – Gaurav

+0

您可以嘗試在'war'任務中添加'update =「true」'。 – lifus

回答

1

您可以嘗試逐步修改war文件:

<target name="war" update="true"> 

您可以初步將圖像包含到war文件中,然後在複製任務中將它們從文件集中排除。

E.g:

<target name="copy" depends="compile"> 
    <copy todir="${build.dir}"> 
     <fileset dir="${web.dir}"> 
      <exclude name="images/**"/> 
     </fileset> 
    </copy> 

您也可以考慮加入duplicate="preserve"螞蟻戰爭任務。它不認爲它與你的問題直接相關,但仍然。

但按manual

請注意,Zip格式允許相同 完全限定名稱的多個文件到一個存檔中存在。這已被記錄爲 導致不知情的用戶的各種問題。如果 希望避免此行爲,則必須將重複屬性設置爲 值,而不是其默認值「添加」。

而且這裏的blog post

+0

在我的index.jsp中有 Gaurav

+0

別擔心。 [這是你的戰爭檔案應該如何](http://documentation.progress.com/output/Iona/orbix/6.1/tutorials/fnb/dev_intro/images/j2ee_overviewa6.gif)。 – lifus

+0

這是一個擁有數千個JSP的非常古老的項目。我無法更改圖像路徑。它的工作原理是這樣的 - 「images/frontpage/emoges/rbdi_revolution.jpg」,但不適用於此 - 「/images/frontpage/emoges/rbdi_revolution.jpg」。而所有JSP的currenlty都有這樣的鏈接 - 「/images/frontpage/emoges/rbdi_revolution.jpg」那我該怎麼辦? – Gaurav