Jump to content
Excelsior Forums
Sign in to follow this  

Sharing compiled SWT DLL amongst EXEs

Recommended Posts

I have multiple JRE-less executables that use SWT.  I would like to compile swt.jar into a DLL that is shared amongst the EXEs (to improve the install size in addition to hopefully the compile time.)  I am not using JET Perfect and I'm using the following versions of products:

JET Pro 3.5 MP3

JDK 1.3.1_06

SWT 3.0 M7 (3038)

My first step was to create SWTWrapper.DLL.  I created a DLL project for swt.jar and forced the whole jar into the project.  I then "unforced" the package org.eclipse.swt.awt so as to remain JRE-less.  Below are the contents of the project file:

%%Excelsior JET v3.50 project file




!module ./swt.jar

!module org/eclipse/swt/SWT.class
!module org/eclipse/swt/SWTError.class
!module org/eclipse/swt/SWTException.class

!batch *.class "org/eclipse/swt/graphics"
!batch *.class "org/eclipse/swt/internal"
!batch *.class "org/eclipse/swt/widgets"
!batch *.class "org/eclipse/swt/events"
!batch *.class "org/eclipse/swt/layout"
!batch *.class "org/eclipse/swt/ole"
!batch *.class "org/eclipse/swt/accessibility"
!batch *.class "org/eclipse/swt/dnd"
!batch *.class "org/eclipse/swt/printing"
!batch *.class "org/eclipse/swt/program"
!batch *.class "org/eclipse/swt/custom"
!batch *.class "org/eclipse/swt/browser"

I then took an EXE project that formerly compiled swt.jar and removed swt.jar using the GUI.  I then closed the GUI and manually added the following line to the project file:

!module SWTWrapper.dll

When I compiled the updated project using a batch file, I received a bunch of warnings but a tiny 10 kb .exe was produced.  The code for this .exe was only 20 or so lines of code, so without SWT that didn't seem impossible.

Here's the list of warnings that were displayed at the end:

List of absent classes:

List of not verifiable classes:
       throws NoClassDefFoundError: org/eclipse/swt/widgets/Composite
files: 1  errors: 0  warnings: 7  notices: 0

When I ran the tiny 10kb .exe that was generated (note that SWTWrapper.dll and swt-win32-3038.dll were in the same directory), I got the error:

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

When I used JetPack and included the 2 SWT DLLs, I received the same error from both the trial run and the resulting executable.

Compiling SWT into a reusable DLL seems like it would be a common situation.  Has anyone else done this successfully?

Share this post

Link to post
Share on other sites

Besides the !module directive, you need to add the 'lookup' directives that points to 'sym' and 'bod' directory of the compiled dll. Please note that it is required that DLL and EXE are compiled in different directories, in order .sym/.bod files to not overlap. So, you should add to the project something like

!module SWTdll.dll

Please refer to the "Dynamic linking" chapter of the JET User's Guide for more details. It can be found online at http://www.excelsior-usa.com/doc/jc008.html#219

Share this post

Link to post
Share on other sites

Thanks.  Adding the sym and bod lookups to the project file worked.

And wow!  Doing this for SWT and JSSE reduced my total file size by about 35% and my compile time by about 80%.

Share this post

Link to post
Share on other sites
Sign in to follow this