Take the 2-minute tour ×

I made a small application with java in Eclipse using SWT for my GUI. I set up the project by installing SWT Designer, which is very similar to Swing Designer only for SWT. I created the project by going to File >> New >> Other >> Window Builder >> SWT Designer >> SWT/JFace Java Project. This set up the whole project for me so I could start using SWT. My program successfully runs when I use Eclipse to run it.

I want to be able to run it without Eclipse, though. I tried to export it as a .jar by going File >> Export >> Java >> JAR file. I selected my project, hit Next >> Next, then I set my main class and hit finish. No errors.

Opening the .jar gave me:

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

It was pretty clear that SWT isn't where it should be, so I opened the .jar and found only my files, the META-INF, etc. No SWT anything. No jar, no org folder, nada.

In my Eclipse project, under the Project Explorer, it lists "Referenced Libraries", where the SWT stuff is set up. When looking under the properties of it, it lists a bunch of org.eclipse... stuff. I assume this is how Eclipse knows what to run, but it seems to not export it.

So my question is: How do I get the project to export with SWT packaged with it, in order to be able to run by the .jar alone? It would be nice if you could explain both the manual way (i.e. editing the META-INF and dragging and dropping the required SWT files) and also explain the Eclipse export way (so I don't have to do the manual way all the time), if there is a way to do it in Eclipse.

EDIT: If you see my answer below, I explained how I was able to get this working, however, it dumps ~16MB worth of code into my .jar, which is pretty big for an originally < 1MB project. If you have any idea on how to make it only add the used files, an answer is still appreciated. ;)

share|improve this question
add comment

2 Answers

Does not sounds like you are using OSGI, my suggestion would be to go to your eclipse plugin directory, grab the swt jar copy it into your plugin and add it to the classpath by going to manifest editor, runtime tab and selecting the jar. If you are running an osgi app, make sure your .product file has the correct dependencies by going to .product editor dependencies tab and selected add required plugins. If you are running this in a different context comment and I will answer.

share|improve this answer
add comment
up vote 0 down vote accepted

The way I successfully made this work, was by exporting it as a runnable JAR.

My steps to getting it working:

Run the main class. (I specifically use CTRL+F11, the default run on the class, letting Eclipse guess how it's supposed to be ran.)

Go to File >> Export >> Runnable JAR.

Select my Launch Configuration. (It's listed when I hit the arrow beside the run button on the top bar on Juno.)

Hit the finish key and wait!

share|improve this answer
add comment

Your Answer


