Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Trouble Exporting SWT Application(Receiving java.lang.NoClassDefFoundError for org.eclipse.swt.widgets.Display)
Trouble Exporting SWT Application [message #650444] Mon, 24 January 2011 23:16 Go to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Trying to export a .jar of my standalone SWT application, but running into some trouble. When I run the exported jar, I get this error:

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

It's apparent to me that Java isn't being told where the SWT library is. When I open up my jar, I see the library where it's supposed to be (in the lib/ sub-directory). Here's my MANIFEST.MF:

Manifest-Version: 1.0
Class-Path: lib/swt.jar
Main-Class: ns.MyApp


So what's the problem? How can I get it to know that SWT is there? Thanks for your help Razz

[Updated on: Mon, 24 January 2011 23:17]

Report message to a moderator

Re: Trouble Exporting SWT Application [message #650483 is a reply to message #650444] Tue, 25 January 2011 08:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
My guess is that the swt.jar you are packaging is only the base bundle
but in case of SWT almost everything is found in the platform specific
fragment.

You don't have to know about the special terms bundle and fragment just
look for an swt-jar e.g. with win32, gtk, cocoa in it and include it.

Tom

Am 25.01.11 00:16, schrieb Jonah Bron:
> Trying to export a .jar of my standalone SWT application, but running
> into some trouble. When I run the exported jar, I get this error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/eclipse/swt/widgets/Display
> It's apparent to me that Java isn't being told where the SWT library
> is. When I open up my jar, I see the library where it's supposed to be
> (in the lib/ sub-directory). Here's my MANIFEST.MF:
>
> Manifest-Version: 1.0
> Class-Path: lib/swt.jar
> Main-Class: ns.MyApp
>
> So what's the problem? How can I get it to know that SWT is there?
> Thanks for your help :p
Re: Trouble Exporting SWT Application [message #650611 is a reply to message #650444] Tue, 25 January 2011 17:15 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
I'm developing on Ubuntu. I downloaded swt-3.6.1-gtk-linux-x86.zip and used the swt.jar file in that zip archive, and it still doesn't work. Here's my project layout if that helps.

MyApp/
    src/
        appns/
            ...
    lib/
        swt.jar (3.6.1-gtk-linux-x86)
        ...
    MANIFEST.MF
    ...
Re: Trouble Exporting SWT Application [message #650757 is a reply to message #650444] Wed, 26 January 2011 12:34 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 01/24/2011 06:16 PM, Jonah Bron wrote:
> Trying to export a .jar of my standalone SWT application, but running
> into some trouble. When I run the exported jar, I get this error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/eclipse/swt/widgets/Display
> It's apparent to me that Java isn't being told where the SWT library is.
> When I open up my jar, I see the library where it's supposed to be (in
> the lib/ sub-directory).

Java doesn't do jars inside other jars. The Class-Path header in a
manifest refers to an external jar/location relative to your jar. As
you have it set up:

app/
standalone.jar
lib/
swt.jar

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Trouble Exporting SWT Application [message #650766 is a reply to message #650757] Wed, 26 January 2011 12:57 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 26.01.11 13:34, schrieb Paul Webster:
> On 01/24/2011 06:16 PM, Jonah Bron wrote:
>> Trying to export a .jar of my standalone SWT application, but running
>> into some trouble. When I run the exported jar, I get this error:
>>
>> Exception in thread "main" java.lang.NoClassDefFoundError:
>> org/eclipse/swt/widgets/Display
>> It's apparent to me that Java isn't being told where the SWT library is.
>> When I open up my jar, I see the library where it's supposed to be (in
>> the lib/ sub-directory).
>
> Java doesn't do jars inside other jars. The Class-Path header in a
> manifest refers to an external jar/location relative to your jar. As
> you have it set up:
>
> app/
> standalone.jar
> lib/
> swt.jar

Right. A standard exporter can't but the Eclipse-Runnable-Jar-Exporter
can export such a thing, so that Jar-In-Jar works!

Tom

>
> PW
>
Re: Trouble Exporting SWT Application [message #650774 is a reply to message #650766] Wed, 26 January 2011 13:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 01/26/2011 07:57 AM, Tom Schindl wrote:
>
> Right. A standard exporter can't but the Eclipse-Runnable-Jar-Exporter
> can export such a thing, so that Jar-In-Jar works!
>

There are also open source apps out there like fatjar that can create
one runnable jar.

Just make sure the software licenses allow you to munge jars together
before you do :-)

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Trouble Exporting SWT Application [message #650825 is a reply to message #650444] Wed, 26 January 2011 17:56 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Awesome, it's working now. Here's my folder layout:

MyApp/
    src/
        appns/
            ...
    publish/
        MyApp.jar (exported)
        swt.jar
    MANIFEST.MF
    ...

Cool. Now, do I just put both the x86 and x86_64 versions in there, and insert two class-paths into the manifest?
Re: Trouble Exporting SWT Application [message #650829 is a reply to message #650444] Wed, 26 January 2011 18:06 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Okay, found out that one must put all libraries into the one class-path. But, if I put the 32-bit library before the 64-bit library, it gives me the "cannot load 32 bit library on 64 bit JVM" error. So I reversed their positions, and it worked. But I'm going to assume that the reverse of that error will come up if I try to run it on a 32-bit system (yes, my computer is 64-bit). How can I get it to automatically select the library it needs?

Edit: and what about media (i.e. images)? Can those be kept in the jar, or do they have to be outside?

[Updated on: Wed, 26 January 2011 18:13]

Report message to a moderator

Re: Trouble Exporting SWT Application [message #651105 is a reply to message #650829] Thu, 27 January 2011 18:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

AFAIK Java won't, the system class path is searched for a class until
the first one found is loaded (which sorts out the native libs in the
SWT case).

You can probably do one of the 4:

1) ship a 32-bit zip and 64-bit zip

2) ship a script with your app that picks the 32/64-bit SWT when
creating the classpath to launch (easier to do on linux than windows)

3) provide a "startup.jar" that determines the system, creates a
URLClassLoader with the correct classpath, and loads/executes your main
class.

4) deploy using JWS/JNLP ... JNLP can specify jars with native resources
on a per-OS basis.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Trouble Exporting SWT Application [message #651135 is a reply to message #650444] Thu, 27 January 2011 22:40 Go to previous message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Okay, I'll probably go with the first option. Thanks for your help Smile
Previous Topic:OLE Automation - disable menubar
Next Topic:Should ExpandBar flicker noticeably when being resized?
Goto Forum:
  


Current Time: Tue Apr 16 17:20:13 GMT 2024

Powered by FUDForum. Page generated in 4.41734 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top