我在eclipse中有一个项目,它使用ant来编译和jar类文件和引用的jar。使用eclipse中默认java构建器生成的类文件生成的jar文件工作正常,但是当使用ant编译源然后jar结果时,错误“错误:尝试打开文件时出现意外错误... .... jar“在目标构建上执行java -jar时的结果。谁知道我做错了什么?下面是构建xml内容。以下是我传给蚂蚁的论据
-DInTouchV.SrcPath = $ {InTouchV.SrcPath} -DInTouchV.DropPath = $ {workspace_loc:/ InTouchVTransferService / dist}
<project default="create_run_jar" name="Create Runnable Jar for Project InTouchVTransferService">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<property name="Version" value="1.3"></property>
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<target name="Compile_Source">
<javac srcdir="${InTouchV.SrcPath}/InTouchVTransferService/src"
destdir="${InTouchV.SrcPath}/InTouchVTransferService/bin"
classpath="${InTouchV.SrcPath}/lib/AtomClasses.jar"
debug="on"
includeantruntime="yes"
/>
</target>
<target name="create_run_jar">
<mkdir dir="${InTouchV.SrcPath}/InTouchVTransferService/bin"/>
<jar destfile="${InTouchV.DropPath}/InTouchVTransferClient.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="com.emdat.inTouchV.main.Main"/>
<attribute name="Class-Path" value="."/>
<section name="common">
<attribute name="Build-Version" value="${Version}"/>
<attribute name="Build-Date" value="${TODAY}"/>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="JVM Version" value="${java.runtime.name} - ${java.runtime.version}" />
</section>
</manifest>
<fileset dir="${InTouchV.SrcPath}/InTouchVTransferService/bin"/>
<zipfileset excludes="META-INF/*.SF" src="${InTouchV.SrcPath}/lib/AtomClasses.jar"/>
</jar>
<touch file="${InTouchV.DropPath}/Version.txt" />
<echo file="${InTouchV.DropPath}/Version.txt">${Version}</echo>
</target>
</project>
答案 0 :(得分:0)
发现问题,属性“JVM Version”包含一个空格。删除了空格,jar文件正确执行。老实说,我不能说为什么eclipse + ant jar的默认java builder与空间一起工作,但是ant build + ant jar didnt。至少它是固定的:D