Search code examples
tomcatspring-mvcwarwinrar

Problem in copy task


When I war a spring mvc project, the war file cannot be deployed to tomcat with ZipException oversubscribed literal/length tree. I find that when I open All files in WEB-INF/LIB/*.jar when I try to open them using winrar I got "unexpected archive file"

I've 2 ant targets that's like this

<target name="build" description="Compile main source tree java files">
        <mkdir dir="${build.dir}" />
        <copy todir="${web.dir}/WEB-INF/">
            <fileset dir="src/main/webapp/WEB-INF/">
                <include name="**/*.*" />
            </fileset>
            <filterchain>
                <striplinecomments>
                    <comment value="!" />
                </striplinecomments>
                <replacetokens>
                    <token key="hibernate.connection.url" value="${hibernate.connection.url}" />
                    <token key="hibernate.connection.username" value="${hibernate.connection.username}" />
                    <token key="hibernate.connection.password" value="${hibernate.connection.password}" />
                    <token key="fontFamily" value="arial, helvetica, sans-serif" />
                </replacetokens>
            </filterchain>
        </copy>
        <copy todir="${build.dir}">
            <fileset dir="src/main/resources">
                <include name="**/*.*" />
            </fileset>
            <filterchain>
                <striplinecomments>
                    <comment value="!" />
                </striplinecomments>
                <replacetokens>
                    <token key="hibernate.connection.url" value="${hibernate.connection.url}" />
                    <token key="hibernate.connection.username" value="${hibernate.connection.username}" />
                    <token key="hibernate.connection.password" value="${hibernate.connection.password}" />
                    <token key="fontFamily" value="arial, helvetica, sans-serif" />
                </replacetokens>
            </filterchain>
        </copy>

        <javac destdir="${build.dir}" source="1.6" target="1.6" debug="true" deprecation="false" optimize="false" failonerror="true">
            <src path="${src.dir}" />
            <classpath refid="master-classpath" />
        </javac>
    </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>

I found now the problem in the copy target, when it copies the *.jar files to an external folder they become corrupted.


Solution

  • I found the problem.

            <copy todir="${web.dir}/WEB-INF/">
                <fileset dir="src/main/webapp/WEB-INF/">
                    <include name="**/*.*" />
                </fileset>
                <filterchain>
                    <striplinecomments>
                        <comment value="!" />
                    </striplinecomments>
                    <replacetokens>
                        <token key="hibernate.connection.url" value="${hibernate.connection.url}" />
                        <token key="hibernate.connection.username" value="${hibernate.connection.username}" />
                        <token key="hibernate.connection.password" value="${hibernate.connection.password}" />
                        <token key="fontFamily" value="arial, helvetica, sans-serif" />
                    </replacetokens>
                </filterchain>
            </copy>
    

    should be

            <copy todir="${web.dir}/WEB-INF/">
                <fileset dir="src/main/webapp/WEB-INF/">
                    <include name="**/*.*" />
                </fileset>
            </copy>