简体   繁体   English

在classpath中使用.jar中的类

[英]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.

相关问题 按类名从类路径中的jar中提取类文件 - Extracting class file from jar in classpath by classname 设置jar和类的类路径 - Setting classpath for a jar and a class 无法从命令提示符下引用类路径中的jar运行Java类 - unable to run java class from command prompt refering to a jar in classpath 如何获取从jar加载的,不在classpath中的任何类作为流? - How to get as a stream any class loaded from a jar not in the classpath? 从JAR依赖关系中提取属性文件,并在自己的类路径中使用它 - Extract properties file from JAR dependency and use it in own classpath 找不到类错误,但是类在类路径中的JAR文件中 - Class not found error, but class is in JAR file on classpath 即使jar在classpath上,也无法找到类异常/调试classpath问题 - Class not found exception even if the jar is on the classpath / debugging classpath problems [TestNG][Jar] Set Classpath in Manifest (Class-Path) — 忽略类路径? - [TestNG][Jar] Set Classpath in Manifest (Class-Path) — classpath is ignored? JAR 中的类文件似乎被忽略了; 而是从类路径上的目录中提取类文件 - class file in JAR seems to be ignored; class file being picked up from directory on classpath instead Gradle (java):测试任务应该使用生成的 .jar 而不是类路径中的 .class 文件 - Gradle (java): test task should use generated .jar and not the .class files in classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM