'找不到主类错误'在构建文件中
我使用 Ant 构建文件创建了一个 Java 应用程序,该文件包含从应用程序生成 jar 文件的 jar-task 任务。
<target name="jar-task" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="jar/guix.jar" basedir="${bin.dir}">
<fileset dir="${basedir}">
<include name="${basedir}/images/**/" />
</fileset>
<manifest>
<attribute name="Main-Class" value="IO.Deep.clk.GUI"/>
<attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/>
</manifest>
<filelist dir="${basedir}" files="user.properties"/>
</jar>
</target>
当我在命令行上执行时,但是出现 NoClassDefFoundError 指出
Could not find the main class IO.Deep.clk.GUI. Program will exit.
Now, the GUI file is正好在特定文件夹和同一个包中,我真的不明白错误可能在哪里......任何人都可以帮忙吗?
I have craated a Java application with an Ant build file containing the jar-task task that generate a jar file from the application.
<target name="jar-task" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="jar/guix.jar" basedir="${bin.dir}">
<fileset dir="${basedir}">
<include name="${basedir}/images/**/" />
</fileset>
<manifest>
<attribute name="Main-Class" value="IO.Deep.clk.GUI"/>
<attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/>
</manifest>
<filelist dir="${basedir}" files="user.properties"/>
</jar>
</target>
When I execute on the command line however a NoClassDefFoundError stating
Could not find the main class IO.Deep.clk.GUI. Program will exit.
Now, the GUI file is exactly in the specific folder and in the same package, I really can't understand where the error may be...can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
名称
images
表明该 jar 文件将仅包含图像。但实际的代码在哪里呢?这件作品
会将完整的限定路径名写入清单中。确定这是正确的吗?另请注意,代码不会通过将文件放在类路径上来找到
user.properties
。类路径只能包含将在其中搜索类或其他内容的目录或 jar 文件。但简单的文件不起作用。我也不确定
lib/*
部分。类IO.Deep.clk.GUI
是否位于该目录中的 jar 文件之一中?这将是一个提示,所有目录都必须明确列出。如果这不是问题 - 很好。编辑:
可以通过添加任务
manifestclasspath
来避免类路径问题(Ant 文档)在调用jar
之前并使用manifest
属性内生成的类路径值。大纲:The name
images
suggests, that the jar file will contain only images. But where is the actual code?This piece
will write full qualified pathnames into the manifest. Are sure, that this is correct? Also note, that the code will not find
user.properties
by putting the file on the classpath. The classpath can contain only directories or jar-files in which classes or other stuff will be searched for. But simple files won't work.I'm also not sure about the
lib/*
part. Is the classIO.Deep.clk.GUI
in one of the jar files in that directory? That would be a hint, that all directories must be listed explicitly. If that's not a problem - good.EDIT:
The classpath problems can be avoided by adding the task
manifestclasspath
(Ant docs) before the call ofjar
and by using the generated classpath value inside themanifest
attribute. Outline:您确定 jar 任务中生成的 filest 包含您需要的所有文件吗?
为了进行调试,您可以使用从 jar 任务转换为文件集的路径并回显它,以便您可以验证是否拥有正确的文件。如果这没问题,那么我在你的文件中没有看到其他错误,尽管我自己对 jar 任务的经验有限。
Are you sure your resulting filest inside the jar task contains all the files you need?
For debugging you can use a path convert to the fileset out of the jar task and echo it so that you can verfiy that you have the correct files. If this is OK then I don't see something else wrong in your file although I have limited experience with the jar task myself.