[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] how to port an swt app to mac os x (carbon)
|
Dear Community,
I struggled to port a Java2 (1.4.1) app based on SWT (3030) to
Mac OS X (>=10.2.6) and produced an application bundle for better
integration with the Mac Desktop and an installable package for Mac.
Because the process was quite undocumented and because I had to compile
so much from a variety of postings, I thought I would share the experiences
of how I eventually succeeded here:
requirements for the mac os x
--------------------------------
- Mac OS X (> 10.2.6)
includes Java2 1.4.1
porting the swt app to mac os x
---------------------------------
- because the java impl. on mac doesn't implement javax.print,
it is necessary to remove all calls to that API.
(e.g. if ( System.getProperty( "os.name" ).indexOf( "Mac" ) >= 0 ))
- before every call to shell.open(), the mac needs another shell.layout()
(there's a bug filed against this, maybe soon it will be obsolete)
- make sure your resources (such as text files) are in a widely-known
encoding: if you created text and property files on win32, they might
be encoded in latin-1 (ISO-5589-1) if you work in Western Europe.
As the world would be a better place if all was UTF-8,
you better convert them using the linux-tool iconv
(e.g. iconv -f ISO_5589-1 -t UTF-8 -o out.utf-8.txt in.latin-1.txt)
- another way is using the Java-Mechanisms:
(e.g. FileInputStream is = new FileInputStream( fileName );
InputStreamReader isr = new InputStreamReader( is, "UTF-8" );
BufferedReader br = new BufferedReader( isr ); )
- download the most accurate and stable SWT jar and jni library (carbon):
<http://www.eclipse.org/platform/index.html>
- download the most accurate and stable eclipse build for mac (carbon).
<http://www.eclipse.org/downloads/index.php>
- extract the java_swt binary from Eclipse.app/Contents/MacOS/,
because you will use this binary instead of the ordinary java to launch.
- try running the swt app using the following command,
assuming that the swt jar-file, the swt jni-file and the Test.class are
all in the current working directory:
java_swt -cp swt-carbon-3030.jar -Djava.library.path=. Test
- once the app works fine, compile a jar file containing your classfiles
and resources (images, properties, text-files)
(e.g. jar -cvf myApp.jar bin local)
building an Application Bundle for tight integration with the OS X GUI
------------------------------------------------------------------------
requirements (can be downloaded at connect.apple.com - register for free):
- December 2002 Mac OS X Developer Tools (300MB)
- Java 1.4.1 Developer Tools Update (50MB): requires the above!
- Create a set of Mac Icons using the "Icon Composer" found under
/Developer/Applications on the Mac.
You simply drag the images into the plots, if necessery,
allow it to scale automatically.
An Application Bundle contains everything that belongs to the app:
- Start /Developer/Applications/Jar Bundler on the Mac.
good tutorial about Jar Bundling can be found under:
<http://developer.apple.com/documentation/Java/Conceptual/Jar_Bundler>
- Jar Bundler creates a MyApp.app bundle/directory, which needs to be
adapted so that it looks like the one below:
MyApp.app
|- Contents
|- Info.plist
|- MacOS
|- java_swt
|- Resources
|- icons.icns
|- Java
|- myApp.jar
|- myResources.jar
|- swt-carbon-3030.jar
|- dll
|- libswt-carbon-3030.jnilib
in detail:
- Replace the "JavaApplicationStub" under "Contents/MacOS" with the
extracted "java_swt" from eclipse
- Under "Java", you place all the jars and external resources that
need to be on the classpath.
- Under "Java/dll", place the libswt...jnilib that you downloaded
from the eclipse-platform project above.
- Adapt the "Info.plist" file to suit java_swt instead of "java":
<key>CFBundleExecutable</key>
<string>java_swt</string>
<key>Java</key>
<dict>
<key>ClassPath</key>
<string>$JAVAROOT/myApp.jar:$JAVAROOT/myResources.jar:
$JAVAROOT/swt-carbon-3030.jar:$JAVAROOT</string>
<key>MainClass</key>
<string>com.blabliblablu.gugus.Main</string>
<key>VMOptions</key>
<string>-Djava.library.path=$JAVAROOT/dll</string>
</dict>
- Your app-bundle should now have the correct icon and should launch
your swt-app upon double-click, should dock into the taskbar when
started and should be right-clickable and utter some meaningful
information there.
building an installable package for the OS X Installer
---------------------------------------------------------
- Put your app-bundle in a seperate directory with nothing else in it.
- If you want the user to see a readme and to accept a license before
installing, create a directory called resources.
In there you can place files like "ReadMe.txt" and "License.txt",
but make sure the naming is exactly like the one here.
- Start /Developer/Applications/Package Maker on the Mac.
good tutorial about Package Maker can be found under:
<http://developer.apple.com/documentation/Java/Conceptual/Jar_Bundler>
- Source files: Point to the directory where the app-bundle resides.
- Resources: Point to the dir. with "ReadMe.txt" and "License.txt"
- "Create Package"
- Try it out by double-clicking the "myApp-1.22.pkg" file
- If you like to burn a hybrid cd for Mac and PC now,
you best do it on the Mac itself:
- insert an empty cd, choose to open it with "Finder" when prompted.
- drag the myApp-1.22.pkg from the Mac HD to the CD
- drag the installer-file for PC "Setup.exe" from a Windows-Share onto
the CD, and another set of ReadMe.txt, License.txt and icon.ico, and,
autorun.inf (containing [autorun] icon=icon.ico open=setup.exe).
I think it is important that the files that should be readable by
a PC are dragged from a PC-Share, and then the Mac creates
automatically an ISO parition for it.
(I might be wrong, but it works fine)
- right-click the cd, choose "burn cd now"
*hope-this-helps-somebody*