Need help running Java program on Mac using swt

Status
Not open for further replies.

electronic_cat

Registered
I am trying to help a friend test a Java program he has which works on XP. I am new to the Mac, and am using my spouse's computer which runs Leopard. The program was built in eclipse using swt and Postgres libraries. On the PC the structure is
dkvBrowser.jar
lib (folder)
swt.jar
postgresql-8.2-506.jdbc3.jar​

and to run it on the PC you just double click. or from cmd, you say
java.exe -jar dkvBrowser.jar

I downloaded the latest OSX swt.jar from eclipse.org, dated 6/25/07

These are the things I have tried:
from terminal,
java -jar dkvBrowser.jar
this gave me "Segmentation fault"

I read about this some, and decided I needed a different swt.jar. I got the version for OSX dated 1/14/2006.

With this, I got
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/events/DragDetectListener


I then moved the jar files in lib to the top level, and added a class path:
java -jar -classpath . DKVBrowser.jar org.dkv.DKVBrowser
this gave:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout

I also tried listing all the jars in the classpath and got a similar message.

(org.dkv.DKVBrowser is the main class name on the manifest in eclipse)

Then I tried building it in JarBuilder. I input the three jar files. The build seemed okay, but when I tried to run it, I got "the application swt quit unexpectedly"

Can anyone suggest something to try?
 
You need to use the appropriate path separator in your classpath. It's a colon with Mac OS X, so $java -cp .:lib/swt.jar:lib/postgres...jar -jar dkvBrowser.jar

Is that really the latest version of SWT you could find? If it's an intel machine you need to make sure it's either universal or i386 because SWT makes use of JNI to call the Carbon API.
 
Thank you for getting back to me. I tried various permutations of what you suggested. The exact statements are shown below. It is an Intel machine, and I think I forgot to say that the friend compiled it in 1.5 since he thought that would work for the Mac. At the Eclipse site I did not see any mention of universal or i386 . There was a place to get the swt.jar for OSX and I did not see any distinction after that. This time I also tried the beta version, with and without debug. But I do not know if the debug went anywhere. The main class name is org.dkv.DKVBrowser -- I did not know if that was necessary or not, but tried it once with each combination.

I hope it is something stupid I am doing, or something he needs to do in the build, and we can figure this out. I think a lot of people with Macs will enjoy this program!

Here are all the things I tried, with the response from terminal underneath:
>>>Current production swt.jar from Eclipse site for OSX
iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar dkvBrowser.jar

org.dkv.DKVBrowser
Segmentation fault

iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
Segmentation fault
******************
>>>Beta version from Eclipse site for OSX dated 11/1/07
iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar

org.dkv.DKVBrowser
Segmentation fault
******************
>>>Try the old version of swt.jar dated 1/14/06

iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
org.dkv.DKVBrowser
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/events/DragDetectListener

iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/events/DragDetectListener

******************
>>> swt-debug.jar renamed to swt.jar
iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout

iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
org.dkv.DKVBrowser
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout

>>>Eclipse swt-debug.jar not renamed
iMac:mac_dkvBrowser tnw$ java -cp .:lib/swt-debug.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar
org.dkv.DKVBrowser

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout
 
Well, after playing around with a test program for a while I was able to get past the segmentation fault by adding this option: -XstartOnFirstThread
 
That got rid of the segmentation error, but I still get
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout

The program is on sourceforge.net if you have time to try it, dkvBrowser.
You won't have the server side of it, but I think it will at least come up. or at least it does in Windows.

Thank you for your efforts.
 
If I replace lib/swt.jar with the swt jar included in eclipse and run the following the program launches.

java -cp .:lib/swt.jar:lib/postgresql-8.2-506.jdbc3.jar -jar DKVBrowser.jar -XstartOnFirstThread
 

Attachments

  • Picture 1.png
    Picture 1.png
    52.6 KB · Views: 2
Wow! I had been reluctant to install Eclipse on someone else's Mac, and had just been downloading the swt.jar. That is great! I'll do it as soon as I can.

One more question, is it obvious where to put the -XstartOnFirstThread in JarBundler? I would like to distribute this so it can be run from the Applications folder.

Thanks again for the extra effort.
 
It doesn't look like you set it from Jar Bundler. After you bundle the application you can edit its Info.plist (Show Package Contents from Finder) and add the following key in the Java dictionary:

Code:
<key>StartOnMainThread</key>
<true/>

Mine looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleAllowMixedLocalizations</key>
	<string>true</string>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleExecutable</key>
	<string>JavaApplicationStub</string>
	<key>CFBundleIconFile</key>
	<string>GenericJavaApp.icns</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>DKVBrowser</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>100.0</string>
	<key>Java</key>
	<dict>
		<key>Arguments</key>
		<string></string>
		<key>ClassPath</key>
		<array>
			<string>$JAVAROOT/DKVBrowser.jar</string>
			<string>$JAVAROOT/postgresql-8.2-506.jdbc3.jar</string>
			<string>$JAVAROOT/swt.jar</string>
		</array>
		<key>JVMVersion</key>
		<string>1.5*</string>
		<key>MainClass</key>
		<string>org.dkv.DKVBrowser</string>
		<key>Properties</key>
		<true/>
		<key>VMOptions</key>
		<string></string>
                [b]<key>StartOnMainThread</key>
		<true/>[/b]
	</dict>
</dict>
</plist>
 
Bottom line, everything works. Without the Info.plist you attached, and the conviction it could be done, I might not have made it. First I downloaded Eclipse Classic 3.3.1.1 OSX and used the swt.jar from that. That gave a message similar to what I had gotten before. Then I downloaded one of the IDE versions and it worked! Both of the swt.jars had the same version number, I think, but they had different dates.

In any case, I have built an installation package, and we are done.

Thank you so much for going above and beyond in your response.

I am closing this thread.
 
Status
Not open for further replies.
Back
Top