无法在mac上运行java程序
我正在尝试运行一个 java 程序,该程序位于名为 udpprobe.client 的包中,但我无法运行该程序。它编译一切顺利,但随后出现错误:
Exception in thread "main" java.lang.NoClassDefFoundError: UDPClient (wrong name: udpprobe/client/UDPClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
有人可以帮助我设置类路径吗?我正在 Mac 上工作。 谢谢
I am trying to run a java program which is in a package named udpprobe.client but I am unable to run the program. It compiles all good but then I get the error:
Exception in thread "main" java.lang.NoClassDefFoundError: UDPClient (wrong name: udpprobe/client/UDPClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could someone help me with the setup of the classpath thing. I'm working on a mac.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试从类文件所在的目录(而不是包的根目录)启动程序时,通常会发生此错误。
在你的例子中,你有一个目录:
带有:
文件,也可能是:
文件。如果您 UDPClient.java 指定了 udpprobe.client 的包,并且尝试从它自己的目录执行它,如下所示:
但是,如果您转到包的基目录并执行完全限定名称,它应该可以工作:
This error occurs typically when you are trying to start a program from the directory the class file is contained in as opposed to the base of the package.
In your case, you have a directory:
With a:
file and possibly also a:
file. You'll get that error if you UDPClient.java specifies a package of udpprobe.client and you try to execute it from it's own directory like this:
However, if you go to the base directory of the package and execute the fully qualified name, it should work: