java代理类未找到异常
我有一个目录结构“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在尝试执行源文件(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
您无法运行
.java
文件,您需要先使用javac
编译它们,然后运行编译后的代码(.class
文件)。在你的例子中,你必须运行然后
You cannot run
.java
files, you need to compile them first withjavac
and then run the compiled code (.class
files). In your example, you have to runand then
您应该引用已编译的 .class 文件,而不是 .java 文件
You should be referencing the compiled .class file, not the .java file
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 specifyAgentMain
on the command line instead ofAgentMain.java
.