使用jar库包编译并执行java程序

发布于 2024-12-04 22:04:45 字数 504 浏览 0 评论 0原文

我正在尝试编译并执行一个使用 JTidy 的 java 程序。我已经设法使用以下命令编译该程序:

javac -classpath jtidy-r938.jar @sourcefile

这似乎工作得很好。但是,当我尝试使用以下命令运行程序时(Top 是包含程序主要部分的类的名称):

java -classpath jtidy-r938.jar Top

我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Top
Caused by: java.lang.ClassNotFoundException: Top
...
Could not find the main class: Top. Program will exit.

这很可能是一个非常愚蠢的问题,有一个简单的解决方案,但它让我发疯了。请帮忙!!

I am trying to compile and execute a java program which uses JTidy. I've managed to compile the program using the following command:

javac -classpath jtidy-r938.jar @sourcefile

This seems to work just fine. However, when I try to run the program with the following command (Top is the name of the class containing the main portion of the program):

java -classpath jtidy-r938.jar Top

I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: Top
Caused by: java.lang.ClassNotFoundException: Top
...
Could not find the main class: Top. Program will exit.

This is mostly likely a very dumb question with a simple solution, but it is driving me insane. Please help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小鸟爱天空丶 2024-12-11 22:04:45

您是否在此处使用类 Top 的完全限定名称,即您的类 Top 是无包的吗?如果没有,您需要提供完全限定的类名才能使上述命令正常工作。确保您还将其他 JAR 依赖项放入类路径中,根据您的目标平台使用 ;: 分隔它们。

编辑:另外,如下所述,如果您的类依赖项不仅在 JAR 中而且也在 .class. (或适当的位置) > 文件系统上的文件。

Are you using the fully qualified name of the class Top here i.e. is your class Top packageless? If not, you need to provide the fully qualified class name for the above command to work. Make sure you also put in other JAR dependencies in the classpath by separating them with ; or : depending on your target platform.

EDIT: Also, as mentioned below, make sure you also include . (or the appropriate location) in your classpath if your class dependencies are not just in the JAR but also .class files on your file system.

蝶舞 2024-12-11 22:04:45

您正在删除路径“.” (当前目录)来自设置时的类路径。

尝试 java -classpath .;jtidy-r938.jar Top 。

这样它应该能够找到您的班级。

You are removing the path "." (current directory) from the classpath when you set it.

Try java -classpath .;jtidy-r938.jar Top.

That way it should be able to find your class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文