File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java lang NoClassDefFoundError with SWT Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java lang NoClassDefFoundError with SWT Class" Watch "java lang NoClassDefFoundError with SWT Class" New topic
Author

java lang NoClassDefFoundError with SWT Class

Sascha Balkau
Greenhorn

Joined: Jan 25, 2006
Posts: 8
Hi,
I'm very new to Java and learning by typing some example code. I've wrote a small class that uses a SWT GUI but I'm getting the following error when I try to run it in the command line (in Eclipse, no probs!) ....

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Decorations

I've tried Java -cp . SWTTest
I also got the path to Java set up correctly (D:\Java\jre1.5.0_06\bin\)
What could be the problem abou this?

Another thing that puzzles me is that another small command line Java class that I'm using now only can be started with ...

java -cp . cmdUtil

but a while back I could start it without the -cp .
(In both cases it was not in a default Java class folder).

Would be cool to figure this out! I've been using the search function and found many topics about this but none of them helped me solving it!
Ramesh Sankar
Greenhorn

Joined: Mar 30, 2006
Posts: 8
the above error is due to the particular jar or lib file is missing ..
open notepad ,copy the content of the program ..save it and run as ordinary java program from command prompt..people like opu should start write coding using notepad..then only u will know about the classes and methods available in java

Thanks
Ramesh.N
Sascha Balkau
Greenhorn

Joined: Jan 25, 2006
Posts: 8
Sorry, I'm not sure what you mean? I should start using Notepad? How does it help me? I'm using Eclipse alot for wrinting ActionScript so I'm not completely unfamiliar with it.

The error looks like some SWT specific stuff is missing but what do I have to do to get this working?

Thanks for any help on this!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

NoClassDefFoundError means that the Java runtime environment can't find a class that your program needs. In 99.9% of the cases, this means your classpath is incorrect.

You are starting your application with: java -cp . SWTTest
So you are only including the current directory (".") in the classpath.

Add the necessary JAR file or directory that contains the SWT classes to your classpath.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Sascha Balkau
Greenhorn

Joined: Jan 25, 2006
Posts: 8
Originally posted by Jesper Young:
NoClassDefFoundError means that the Java runtime environment can't find a class that your program needs. In 99.9% of the cases, this means your classpath is incorrect.

You are starting your application with: java -cp . SWTTest
So you are only including the current directory (".") in the classpath.

Add the necessary JAR file or directory that contains the SWT classes to your classpath.


Ok, I get what you mean! Now I'm trying it with the following ...

>java -cp "D:\Eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.1.2.jar" SWTDemo

I've also added a . to the CLASSPATH env variable so I don't need the -cp .
but it still doesn't work and gives me an error, this time only a java.lang.NoClassDefFoundError. Obviously it's the correct jar file for the SWT classes but something is still wrong.
[ April 21, 2006: Message edited by: Sascha Balkau ]
Sascha Balkau
Greenhorn

Joined: Jan 25, 2006
Posts: 8
I've figured it out finally!
For the afterworld:

Download the standalone SWT library and DLL's ...
http://www.eclipse.org/swt/

unpack swt.jar to your JRE/lib folder, copy the three swt...dll to your JRE/bin folder (ideally).
On the environment variable CLASSPATH add .;path/to/JRE/lib
On the environment variable PATH add path/to/JRE/bin (if not already there)

now SWT Java apps should be able to run on the command line by simply using
Java YourApp.

... always refreshing that nowhere guides can be found that explain this! :/
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 481
    
    1

Thank you so much @Sascha. You really helped me out!


True person is moral, false is right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java lang NoClassDefFoundError with SWT Class
 
Similar Threads
listening to another thread
can't compile ANYWHERE...
Problem running swt in command line
SWT versus Swing/awt
what exactly setting a classpath means?