java代理类未找到异常

发布于 2024-12-16 16:50:30 字数 388 浏览 3 评论 0原文

我有一个目录结构“D:\workspace 2\project\lib”,其中包含所有文件“AgentMain.java”(我从 src 复制并将其放在此处以使其更容易)、“asm-all.3.3.3”。 jar”、“myagent.jar”。现在,当我尝试从命令提示符调用我的 java 程序时,

D:\workspace 2\project\lib>java -javaagent:myagent.jar -cp asm-all-3.3.jar;. AgentMain.java

它在线程 main java.lang.NoclassDefFoundError AgentMain/java 中给出异常,并说找不到主类 AgentMain.java

这里出了什么问题?

I have a directory structure "D:\workspace 2\project\lib" where I have all the files "AgentMain.java"(which I copied from src and placed it here to make it easier), "asm-all.3.3.jar", "myagent.jar". Now when I try to invoke my java program like this from command prompt

D:\workspace 2\project\lib>java -javaagent:myagent.jar -cp asm-all-3.3.jar;. AgentMain.java

it gives me exception in thread main java.lang.NoclassDefFoundError AgentMain/java and says couldnot find the main class AgentMain.java

What is wrong here?

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

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

发布评论

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

评论(4

晨敛清荷 2024-12-23 16:50:30

您正在尝试执行源文件(AgentMain.java)而不是该类。确保您已使用 javac 编译了 AgentMain,然后删除 .java 文件扩展名。

根据评论的讨论进行更新:
由于一旦编译您的类,您的 AgentMain 类就定义在名为“main”的包中,因此其相应的类文件必须位于名为“main”的目录中。

因此,如果您使用包含的命令从“d:\workspace 2\project\lib”目录运行,则编译后的类需要位于 d:\workspace 2\project\lib\main\AgentMain.class 中

You're trying to execute your source file (AgentMain.java) instead of the class. Make sure you've compiled AgentMain with javac and then remove the .java file extension.

UPDATE based on discussion from the comments:
Since your AgentMain class is defined in a package called "main" once you compile your class, its corresponding class file must be in a directory called "main".

so if you're running from your "d:\workspace 2\project\lib" directory with the command you included, the compiled class needs to be in d:\workspace 2\project\lib\main\AgentMain.class

枯寂 2024-12-23 16:50:30

您无法运行.java文件,您需要先使用javac编译它们,然后运行编译后的代码(.class文件)。在你的例子中,你必须运行

javac -cp asm-all-3.3.jar;. AgentMain.java

然后

java -javaagent:myagent.jar -cp asm-all-3.3.jar;. AgentMain

You cannot run .java files, you need to compile them first with javac and then run the compiled code (.class files). In your example, you have to run

javac -cp asm-all-3.3.jar;. AgentMain.java

and then

java -javaagent:myagent.jar -cp asm-all-3.3.jar;. AgentMain
情话难免假 2024-12-23 16:50:30

您应该引用已编译的 .class 文件,而不是 .java 文件

You should be referencing the compiled .class file, not the .java file

彻夜缠绵 2024-12-23 16:50:30

java 不解释源文件。

您必须首先使用 javac 编译 AgentMain.java。然后您必须在命令行上指定 AgentMain 而不是 AgentMain.java

java does not interpret source files.

You have to compile AgentMain.java with javac first. Then you have to specify AgentMain on the command line instead of AgentMain.java.

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