我有一个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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.java:115
: cannot find symbol
[javac] symbol : class Label
[javac] location: class com.demo.ant.WriteHelper
[javac] Label label;
[javac] ^
[javac] C:\Users\FSSD\workspace\Ex_Ant\src\com\demo\ant\WriteHelper.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:\Users\FSSD\workspace\Ex_Ant\build.xml:7: Compile failed; see the compiler err
or output for details.
Total time: 2 seconds
可能是什么原因?
我的蚂蚁文件如下:
<?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>
答案 0 :(得分:1)
编译类时,您没有加载Java库。做这样的事情:
将其添加到您的ant文件中:
<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 [如果你有任何默认的java lib]提供jar文件夹的路径。
答案 1 :(得分:0)
似乎导入了Label或缺少相应的类路径条目。您是否已成功编译该代码?
将<classpath>
元素添加到<javac>
元素。
答案 2 :(得分:0)
使用什么编辑器?你能在编辑器中编译吗?如果是,那么您需要在构建文件中定义类路径(类似于编辑器中的类路径)。