Java -CP错误:找不到或加载Main类(Java.lang.classnotfoundexception)

发布于 2025-01-30 15:24:24 字数 826 浏览 2 评论 0原文

我基本上要关注下一个教程: https://picococli.info/#_running_running_the_papplication_the_papplication

尝试使用下一个命令运行我的应用程序:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" src/main/java/TestPicoCli.java --algorithm SHA-1 hello.txt

我位于一个目录中,其中有2个Jars picoclibashtool,但是我将获得下一个错误消息:

Error: Could not find or load main class src.main.java.TestPr.java
Caused by: java.lang.ClassNotFoundException: src.main.java.TestPr.java

这就是y目录的样子:

”在此处输入图像描述

有什么想法吗?

I'm basically following the next tutorial: https://picocli.info/#_running_the_application

And I'm trying to run my Application with the next command:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" src/main/java/TestPicoCli.java --algorithm SHA-1 hello.txt

I'm located in a directory where I have the 2 jars picocli and bashTool, but I'm getting the next error message:

Error: Could not find or load main class src.main.java.TestPr.java
Caused by: java.lang.ClassNotFoundException: src.main.java.TestPr.java

This is how y directory looks like:

enter image description here

Any ideas?

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

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

发布评论

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

评论(2

薄暮涼年 2025-02-06 15:24:24

尝试java -cp“ picocli-4.6.3.jar:bashtool-1.0-snapshot.jar” testpicocli -algorithm sha-sha-1 hello.txt

Try java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" TestPicoCli --algorithm SHA-1 hello.txt

帅的被狗咬 2025-02-06 15:24:24

命令java可以执行编译(字节)Java文件.class
您正在尝试执行源文件.java,但这是不正确的。

首先,您需要查找testpicocli.class文件。它可以由您的IDE生成,并且可能在target/class

,那么,如果您在包含testpicocli.class的文件夹中,则必须运行:

java -cp "<path_to_your_jar>/picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" TestPicoCli // Without .class

或者如果您在包含.jar的文件夹中,您应该运行:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar;<path_to_class_file>" TestPicoCli

注意:如果您在Linux上,请替换; 用> :

The command java can execute a compiled (bytecode) Java file .class
You are trying to execute a source file .java and it is not correct.

First, you need to find the TestPicoCli.class file. It could be generated by your IDE and is possibly in target/classes

Then, if you are in the folder that contains the TestPicoCli.class, you have to run:

java -cp "<path_to_your_jar>/picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" TestPicoCli // Without .class

Or if you are in the folder that contains the .jar, you should run:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar;<path_to_class_file>" TestPicoCli

Note: If you are on Linux, replace ; with :

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