Getting exception when trying to run swing code via ANT
I have a Java swing code, I wish to execute this code via Ant. But when I do that I get following exception:
[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\sr开发者_JS百科c\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
What could be the reason?
My ant file is as follow:
<?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>
You are not loading java libraries while compiling your class. Do something like this:
Add this to your ant file:
<path id="project.class.path">
<pathelement location="src" />
<pathelement path="${java.class.path}/" />
</path>
then in compile task:
<property name="cp" refid="project.class.path" />
<javac srcdir="src" destdir="build/classes" classpath="${cp}">
</javac>
Here in <pathelement location="src" />
give relative path to src
from where the ant file is located. Or you can also give absolute path.
You may also need to add more class path dependency based on your application. In short give path to jar folder of all required jars[If you have any beside default java lib] in project.class.path
.
Seems like either an import of Label or the corresponding class path entry is missing. Did you compile that code successfully already?
Add a <classpath>
element to the <javac>
element.
What editor do use? Can you compile in your editor? If yes, so you need to define your classpath (similar to what you have in your editor) in the build file.
精彩评论