使用javac编译时出现问题
当我尝试使用 javac 任务进行编译时。我在控制台中什么也没有得到。以前,我得到了一些有关我正在编译的内容的信息,例如 [javac] "...."
当我清理并重新编译它时,它可以工作,我可以看到输出,但当我再次编译时,问题出现了。
同样,这个问题以前并不存在。这个问题使 tomcat 抱怨 .war 文件,它说“ZipException:过度订阅的文字/长度树”
有人可以指导我解决这个问题吗?
编辑:这是 ant 脚本的相关部分
<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>
请注意:之前在相同的文件上运行得很好。现在,如果不更改项目内部的任何内容,它就无法工作
请注意:我的项目正在工作,并且我已将其存档。它编译得很完美,我什至把存档文件给了一些人,它正在与他们一起工作。然后,我做了一些修改,直到得到 ZipException。 之后,我保留了修改并使用了正在运行的旧存档文件,但我仍然收到相同的错误 ZipException。所以,问题绝对不是源代码或 ant 脚本。我相信这是我的环境中的问题,但我无法弄清楚出了什么问题。
build.xml文件如下:
<?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="${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>
<move todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war" />
</fileset>
</move>
</target>
</project>
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="${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>
<move todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war" />
</fileset>
</move>
</target>
</project>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现了问题。
应该是
然后一切就OK了。
I found the problem.
should be
and then everything is OK.
谷歌搜索该异常消息表明这是由于您(Tomcat)尝试读取的 ZIP 文件损坏所致。为了找出它被损坏的原因,我们需要有关如何构建 WAR 文件的更多信息。
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.
我会尝试删除由 clean 删除的各种构建工件,以查看哪些导致了问题。希望这能让人们对问题有足够的了解并解决问题。
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 的编译器任务是智能的,如果它检测到输出类比源类新,那么编译器就会得出结论,该类一定是已经从源代码构建的。在这种情况下,编译器将不执行任何操作(因为已检测到工作已完成)。
当编译器什么都不做时,就没有输出。
第一次编译后,打开源文件,进行一些细微的更改(例如注释),然后保存文件。这将使源比现有的编译类更新。然后,当您调用 Ant 任务来构建类时,javac 任务将检测到源比该类更新,并且它将重新编译源文件,生成新的类文件。
既然 javac 任务会做一些事情,那么它就会有一些东西要报告;因此,您应该看到一些输出(但比您必须构建所有内容时要少)。
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).