简体   繁体   English

无法在mac上运行java程序

[英]unable to run a java program on 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. 我正在尝试运行一个名为udpprobe.client的程序包中的java程序,但我无法运行该程序。 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. 我正在研究一台Mac。 Thanks 谢谢

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: 在您的情况下,您有一个目录:

/some/path/to/udpprobe/client/ /一些/路径/到/ udpprobe /客户机/

With a: 用:

UDPClient.class UDPClient.class

file and possibly also a: 文件,也可能是:

UDPClient.java UDPClient.java

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: 如果您的UDPClient.java指定了一个udpprobe.client包,并且您尝试从它自己的目录执行它,您会收到该错误,如下所示:

/some/path/to/udpprobe/client$ java UDPClient / some / path / to / udpprobe / client $ java UDPClient

However, if you go to the base directory of the package and execute the fully qualified name, it should work: 但是,如果您转到包的基目录并执行完全限定名称,它应该工作:

/some/path/to$ java udpprobe.client.UDPClient / some / path / to $ java udpprobe.client.UDPClient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM