我在 Eclipse 中的第一次 ant 构建遇到了一些麻烦,这是我的 build.xml 构建文件。
<project name="Rutherford" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="libs" value="libs"/>
<path id="classpath">
<fileset dir="${libs}" includes="**/*.jar"/>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" classpathref="classpath">
<compilerarg line="-encoding utf-8"/>
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="nat.rutherford.DesktopStarter"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="${dist}/MyProject-${DSTAMP}.jar" fork="true"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
它编译正常,没有警告或错误,但是当我尝试运行 .jar 时,它显示“找不到主类:nat.rutherford.DesktopStarter。程序现在将退出' =(
我已经阅读了大量关于此事的页面,但到目前为止还没有定论。
我能够使用 Eclipse -> File -> Export -> Java -> Runnable Jar File 编译它。但是我使用了一些 UTF-8 编码的 .txt 文件,它们似乎无法以这种方式处理,我需要它们!即我有希腊字符应该读...dσ/dΩ...但目前读... dÃ/d©...这是行不通的^^
所以基本上我需要让我的 Ant 构建工作,记住它也需要能够处理我的 UTF-8 编码的 .txt 文件。