我有一个Java swing代码,我希望通过Ant执行这个代码。但当我这样做时,我会得到以下异常:
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label7=new Label(cval,k,JavaSamp.install_c
ountlist.get(z),timesBoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:102
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label7=new Label(cval,k,JavaSamp.install_c
ountlist.get(z),timesBoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:104
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label8=new Label(8,k,JavaSamp.maxval,times
BoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:104
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label8=new Label(8,k,JavaSamp.maxval,times
BoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:106
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label9=new Label(9,k,JavaSamp.maxsysval,ti
mesBoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:106
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label9=new Label(9,k,JavaSamp.maxsysval,ti
mesBoldUnderline);
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:115
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label;
[javac] ^
[javac] C:UsersFSSDworkspaceEx_AntsrccomdemoantWriteHelper.java:116
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] label = new Label(column, row, s, timesBoldUnderline);
[javac] ^
[javac] 83 errors
BUILD FAILED
C:UsersFSSDworkspaceEx_Antbuild.xml:7: Compile failed; see the compiler err
or output for details.
Total time: 2 seconds
原因可能是什么?
我的ant文件如下:
<?xml version="1.0" ?>
<project name="Ant Example" default="execute">
<target name="init" depends="clean">
<mkdir dir="build/classes" />
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="build/classes" />
</target>
<target name="execute" depends="compile">
<java classname="com.demo.ant.JavaSamp" classpath="build/classes" />
</target>
<target name="clean">
<delete dir="build" />
</target>
</project>
编译类时没有加载java库。这样做:
将此添加到您的蚂蚁文件:
<path id="project.class.path">
<pathelement location="src" />
<pathelement path="${java.class.path}/" />
</path>
然后在编译任务中:
<property name="cp" refid="project.class.path" />
<javac srcdir="src" destdir="build/classes" classpath="${cp}">
</javac>
在<pathelement location="src" />
中,给出ant文件所在的src
的相对路径。或者你也可以给出绝对路径。
您可能还需要根据应用程序添加更多的类路径依赖项。简而言之,在project.class.path
中给出所有所需jar的jar文件夹的路径[如果您有默认的javalib]。
似乎缺少Label的导入或相应的类路径条目。你已经成功编译了那个代码吗?
将<classpath>
元素添加到<javac>
元素中。
使用什么编辑器?你能在编辑器中编译吗?如果是,那么您需要在构建文件中定义类路径(类似于编辑器中的类路径)。