[英]use class from .jar in classpath
when I try to use some class, for example Layout, in swt.jar
by cmd it complains me about not having it, this is the message error: 当我尝试使用某些类,例如布局,在cmd的swt.jar
它抱怨我没有它,这是消息错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout 线程“main”中的异常java.lang.NoClassDefFoundError:org / eclipse / swt / widgets / Layout
The weird thing is, swt.jar
is in \\ext
directory and my CLASSPATH is C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\ext
奇怪的是, swt.jar
位于\\ext
目录中,我的CLASSPATH是C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\ext
When I create a new project in eclipse there's no problem, all imports from this jar works fine, but on cmd I'm getting this error. 当我在eclipse中创建一个新项目没有问题时,从这个jar的所有导入工作正常,但在cmd我得到这个错误。
Help me please! 请帮帮我!
You need to set the classpath till the Jar File
, to use a class under that Jar File
您需要将类路径设置为Jar File
,以使用该Jar File
下的类
C:\Program Files\Java\jdk1.6.0_26\jre\lib\ext\swt.jar
Just a suggestion: - Don't put your Jar files in the ext
directory. 只是一个建议: - 不要将你的Jar文件放在ext
目录中。 Put it somewhere else. 把它放在其他地方。
As far as Eclipse
is concerned, it does not uses the System Classpath
set in the environment variable. 就Eclipse
而言,它不使用环境变量中设置的System Classpath
。 You should put the Jar File
in a lib
directory under your project while using in Eclipse and add the Jar File
to your BuildPath. 在Eclipse中使用时,应将Jar File
放在项目下的lib
目录中,并将Jar File
添加到BuildPath中。
You're learning a hard lesson: IDEs, including Eclipse, and Java EE app servers, like Tomcat, pay no attention to any environment variables like CLASSPATH. 您正在学到一个艰难的教训:IDE(包括Eclipse)和Java EE应用服务器(如Tomcat)不关注CLASSPATH等任何环境变量。
I don't think a JAR like swt.jar belongs in the jre/lib/ext directory. 我不认为像swt.jar这样的JAR属于jre / lib / ext目录。 That should only be for JVM extensions from Oracle. 这应该只适用于Oracle的JVM扩展。
You should add that to your project /lib directory, along with all other 3rd party JARs, and set CLASSPATH in Eclipse and startup scripts properly. 您应该将它与所有其他第三方JAR一起添加到project / lib目录中,并在Eclipse和启动脚本中正确设置CLASSPATH。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.