tomcat - 在 tomcat 上部署 war 时如何跳过图像

标签 tomcat war

我有一个 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/

相关文章:

deployment - FAIL - 上下文路径/Hello 中的应用程序无法启动

java - war 文件没有爆炸的原因可能是什么?

java - 无法打开 neo4j DB

web-applications - 是否将新的 .war 文件上传到 webapps 目录以强制重启 tomcat?

java - 通过 Tomcat 进行 SQL Server Windows 身份验证

Java SpringMVC Autowiring BeanCreationException

war - 在 src/main/webapp 中过滤文件子集的 gradle 方法是什么?

web-applications - 使用 gradle 创建一个包含 webapp 中的类的 JAR

gradle - gradle war插件中的baseName和archivesBaseName有什么区别?

java - 没有任何根本原因的 IllegalStateException