简体   繁体   English

线程“ main”中的异常java.lang.NoClassDefFoundError:设置PATh和CLASSPATH之后

[英]Exception in thread “main” java.lang.NoClassDefFoundError:after setting PATh and CLASSPATH

I have tried to write a program where i want to access class in a jar. 我试图编写一个我想访问jar中的类的程序。

I am using netbeans as ide,Windows 7 os and have added jar in the libraries. 我使用netbeans作为ide,Windows 7 os,并在库中添加了jar。 But i keep getting the error. 但是我一直在出错。

Exception in thread “main” java.lang.NoClassDefFoundError:after setting PATh and CLASSPATH



I have set the PATh variable to my <jdk directory>/bin;
CLASSPATH to %CLASSPATH%;
and JAVA_HOME to <jdk directory>

<jdk directory> =C:\Program Files\Java\jdk1.7.2

You've just learned an important lesson: Java ignores CLASSPATH environment variable. 您刚刚学到了重要的一课:Java忽略CLASSPATH环境变量。

You need the PATH to your JAVA/bin for your own convenience, but the CLASSPATH is not useful. 为了您自己的方便,您需要JAVA / bin的PATH,但是CLASSPATH没什么用。 I don't have one on any machine I work with. 我使用的任何计算机上都没有。

You can see why: they're so idiosyncratic and specific to a given project. 您会看到原因:它们是如此特质,特定于给定的项目。

You should learn how to set it using -cp option on javac.exe and java.exe. 您应该学习如何在javac.exe和java.exe上使用-cp选项设置它。 You can use Ant to build for more complex projects. 您可以使用Ant构建更复杂的项目。 And if you deploy to a Java EE app server, you need to understand the classloader hierarchy. 而且,如果部署到Java EE应用服务器,则需要了解类加载器的层次结构。

If you insist on using NetBeans, I'd recommend looking in the help to see how it wants you to set CLASSPATH. 如果您坚持使用NetBeans,建议您查看帮助以了解它如何设置CLASSPATH。

You should have the jar file in your classpath to access the classes inside it. 您应该在类路径中具有jar文件,以访问其中的类。 Moreover when you run a program from an IDE it overrides any classpath settings you do at system level. 此外,当您从IDE运行程序时,它会覆盖您在系统级别执行的任何类路径设置。 Please check your build path in the IDE. 请在IDE中检查您的构建路径。

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

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