简体   繁体   English

Classpath导出成功,java Class.class调用错误

[英]Classpath exported OK,java Class.class invokes error

executed ok: 执行确定:

export CLASSPATH=/home/sergio/workspace/teal

Anon.class resides in teal directory Anon.class驻留在teal目录中

both java Anon or java -cp /home/sergio/workspace/teal Anon invoke classical: java Anonjava -cp /home/sergio/workspace/teal Anon调用经典:

Exception in thread "main" java.lang.NoClassDefFoundError: Anon

Have I missed something in CLASSPATH declaration? 我是否错过了CLASSPATH声明中的某些内容?

If the package of your class is teal , you should be exporting the classpath "till" the package directory, not into it. 如果您的类的包是teal ,那么您应该将类​​路径“直到”导出到包目录,而不是导出到该目录。

export CLASSPATH=/home/sergio/workspace/

To make it more generic, if the package of a class Bar is com.foo and the directory structure looks like, 为了使其更通用,如果Bar类的包是com.foo并且目录结构看起来像这样,

[+] classes/
[+]    com/
[+]        foo/
[-]            Bar.class

You should set classpath till classes only. 您应该将类​​路径设置为仅classes

You need to have "." 您需要输入“。” in your classpath. 在你的classpath中。

For Unix this is done with 对于Unix,这是通过

export CLASSPATH=/home/sergio/workspace/teal:.

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

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