受@ leeand00提供的链接启发,我提出了以下解决方法。
首先,我编写了一个简单的Perl脚本(称为
genClasspath.pl),该脚本生成
.classpathEclipse使用的文件。
#!/usr/bin/perluse strict;if (@ARGV != 2) { print STDERR "Usage: $0 OUTFILe CLASSPATHSTRINGn"; print STDERR "e.g., $0 .classpath path1:path2:path3n"; exit 1;}my $OUTFILe = $ARGV[0];my $CLASSPATHSTRING = $ARGV[1];open my $out_fh, '>', $OUTFILe or die "Couldn't open output file: $!";print $out_fh q{<?xml version="1.0" encoding="UTF-8"?><classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="build"/>};my @libs = split(":", $CLASSPATHSTRING);foreach my $thisLib (@libs){ print $out_fh " <classpathentry kind="lib" path="$thisLib"/>n";}print $out_fh "</classpath>n";然后,我将
build.xml文件的内容调用此脚本
dep.runtime:
<target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}" debug="on" includeantruntime="false"> <classpath refid="dep.runtime" /> </javac> <property name="myclasspath" refid="dep.runtime"/> <exec dir="." executable="../../scripts/genClasspath.pl" os="Linux"> <arg value=".classpath"/> <arg value="${myclasspath}"/> </exec></target>唯一的问题是,在Eclipse中打开项目之前,我至少需要在命令行上运行一次Ant。但是,当我这样做时,Eclipse可以很好地编译和执行我的项目,因为类路径与Ant的完全相同。



