简体   繁体   中英

java , eclipse jar problem

i'm kind of new to java. I use eclipse and i imported some jar files with some classes by going to properties -> Add External Jars; The problem is that when i try to use a class from the jar i get the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: nextapp/echo2/app/event/ActionListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at Program.main(Program.java:12) Caused by: java.lang.ClassNotFoundException: nextapp.echo2.app.event.ActionListener at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 13 more

The class is supposed to create a window, i guess that the jar has to import somehow other stuff or something like that, How can i fix this?

PS. Sorry for the bad code , i don't know tags here.

thansk, Raxvan

Most jars you download will include 0-5 other jars that are needed. They all need included in order to use the jar. Very quickly you end up with 20 jars in a simple 1000 line Java project, but thems are the breaks.

Look inside your downloaded jar zip. Should be a lib directory or such with all the libs you need.

Another way to get around this would be to use a tool like Ivy or Maven to manage downloading dependencies. Depending on what libraries you are using, you may have many transitive dependencies, and doing that all by hand will end up taking a lot of time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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