2013-08-03 106 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