开发者

Problem when compiling using javac

开发者 https://www.devze.com 2023-03-18 06:18 出处:网络
When I try to compile using javac task. I don\'t get anything in the console. Previously, I was getting some info about what I\'m compiling for example [javac] \".... \"

When I try to compile using javac task. I don't get anything in the console. Previously, I was getting some info about what I'm compiling for example [javac] ".... "

When, I clean and recompile it works and I can see the output, but the problem appears when I compile again.

Again, this problem didn't exist previously. And this problem makes tomcat complains about the .war file it says "ZipException: oversubscribed literal/length tree"

Could anyone guide me in this problem?

EDIT: Here is the relevant part of the ant script

<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>   

Please NOTE: That was working very well previously on the same files. now without changing anything inside the project it doesn't work

Please NOTE: I've the project that was working and I've archived it. It was compiling perfect and I gave the archive file to some people even and it was working with them. Then, I've made some modifications till I got the ZipException. After that I kept the modification away and used the old archive file that was working and I still get the same error ZipException. So, the problem is DEFINITELY NOT the source code or the ant script. I believe it's a problem in my environment but I cannot figure out what has gone wrong.

The build.xml file is as follow:

<?xml version="1.0"?>
<!DOCTYPE project>
<project name="GameServerPart1" basedir="." default="usage">
    <property file="../build.properties" />

    <property name="src.dir" value="src/main/java" />
    <property name="web.dir" value="war" />
    <property name="build.dir" value="${web.dir}/WEB-INF/classes" />
    <property name="name" value="GameServerPart1" />

    <path id="master-classpath">
        <fileset dir="src/main/webapp/WEB-INF/lib">
            <include name="*.jar" />
        </fileset>
        <!-- We need the servlet API classes: -->
        <!--  * for Tomcat 5/6 use servlet-api.jar -->
        <!--  * for other app servers - check the docs -->
        <!--<fileset dir="${appserver.lib}">
            <include name="servlet*.jar"/>
        </fileset> -->
        <pathelement path="${build.dir}" />
    </path>

    <target name="usage">
        <echo message="" />
        <echo message="${name} build file" />
        <echo message="-----------------------------------" />
        <echo message="" />
        <echo message="Available targets are:" />
        <echo message="" />
        <echo message="build     --> Build the application" />
        <echo message="deploy    --> Deploy application as directory" />
        <echo message="deploywar --> Deploy application as a WAR file" />
        <echo message="cleanr    --> clean the build." />
        <echo message="" />
    </target>

    <target name="clean">
        <delete dir="${web.dir}" />
    </target>

    <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="${hi开发者_如何学编程bernate.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>
        <move todir="${deploy.path}" preservelastmodified="true">
            <fileset dir=".">
                <include name="*.war" />
            </fileset>
        </move>
    </target>

</project>


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>

and then everything is OK.


Googling that exception message suggests that it is due to corruption of the ZIP file you are (Tomcat is) trying to read. To figure out why it gets corrupted, we'll need more information on how you are building the WAR file.


I'd try getting rid of various sets of build artifacts that are deleted by clean, to see which are causing the problem. Hopefully, this will give enough insight into the problem to figure it out.


Ant's compiler task is intelligent, in the sense that if it detects that the output class is newer than the source class, then the compiler concludes that the class must have been built from the source code already. In such a circumstance, the compiler will do nothing (because the work was already detected to be done).

When the compiler does enough of nothing, then there is no output.

After the first compile, open a source file, make some trivial change (a comment for example) and then save the file. This will make the source newer than the existing compiled class. When you then call the Ant task to build the classes, the javac task will detect that the source is newer than that class, and it will recompile the source file generating new class file(s).

Since the javac task will be doing something, then it will have something to report; so, you should see a bit of output (but less than if you have to build everything).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号