我有一个 Java 网络应用程序。我正在使用 ant 文件将其作为 war 部署到 Tomcat 服务器上。我可以成功做到这一点。请在下面找到 build.xml 现在的挑战是我的应用程序中的 web 文件夹下有 100000 张图像,这些图像被复制到 war 根文件夹。
如果我在 war 文件的根文件夹中创建一个包含 100000 个图像的 war,那将是一件令人头疼的事情。
每次我更改 JSP 或 java 代码中的任何内容时,新的 war 将再次复制 war 文件夹中的那 100000 张图像,这需要超过 1 小时来构建 war 文件。
我如何确保我在 war 中的图像文件夹不会在每次部署时一次又一次地被复制?
<!-- 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>
最佳答案
您可以尝试增量修改 war 文件:
<target name="war" update="true">
您可以预先将图像包含到 war 文件中,然后在复制任务中将它们从文件集中排除。
例如:
<target name="copy" depends="compile">
<copy todir="${build.dir}">
<fileset dir="${web.dir}">
<exclude name="images/**"/>
</fileset>
</copy>
您也可以考虑将 duplicate="preserve"
添加到 ant war 任务中。它认为它与您的问题没有直接关系,但仍然。
但根据 manual :
Please note that the Zip format allows multiple files of the same fully-qualified name to exist within a single archive. This has been documented as causing various problems for unsuspecting users. If you wish to avoid this behavior you must set the duplicate attribute to a value other than its default, "add".
还有这里的 blog post .
关于tomcat - 在 tomcat 上部署 war 时如何跳过图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18038194/