gpt4 book ai didi

java - 尝试通过 ANT 运行 swing 代码时出现异常

转载 作者:行者123 更新时间:2023-12-01 15:49:12 25 4
gpt4 key购买 nike

我有一个 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

可能是什么原因?

我的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 库。做这样的事情:

将其添加到您的 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" />给出 src 的相对路径ant 文件所在的位置。或者你也可以给出绝对路径。

您可能还需要根据您的应用程序添加更多类路径依赖项。简而言之,在 project.class.path 中给出所有必需 jar 的 jar 文件夹的路径[如果除了默认 java lib 之外还有任何的话] .

关于java - 尝试通过 ANT 运行 swing 代码时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6467212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com