Running Java Applications on Mac OS X
Pages: 1, 2
|
|
If you click on the green button, there can be a redrawing problem with the larger window that is corrected if you do a live resize by grabbing the lower-right corner. There's more, however, to the Mac experience than just being able to use the genie effect while shrinking JUnit down to the dock. In the next section, we'll look at making the user experience more Mac-like.
Creating a double-clickable version
You don't want a user to have to navigate to the right directory and type in the class path every time they run JUnit. One of the cool things Apple did in shipping Mac OS X was to ship the developer tools along with the operating system. We'll use MRJAppBuilder to quickly package JUnit up as a double-clickable app. You'll find MRJAppBuilder in the /Developer/Applications/ directory. Start it up and let's start filling in the various fields in the Application tab pane.

In our first shot, let's fill in the fields with the same values we used from the command line. There the main class name was junit.swingui.TestRunner and the class path was [Install Dir]/junit3.7/junit.jar:. . This class path is interesting because it uses one absolution path and one relative path. The "." assumes that we're inside of the [Install Dir]/junit3.7 directory, so we're forced to put our output file there. We could change the "." to an absolute path and place the output file anywhere. For now, we choose the clever name junit.app for our output file and set the fully qualified name as [Install Dir]/junit3.7/junit.app.
This is fine if you are just creating a quick application that will sit on your own machine. If you use absolute paths, you can move junit.app anywhere on your machine. On the other hand, if you are interested in using this technique to deploy applications to other users, you should use relative paths. This way your application is not dependent on the directory structure of the user's machine. In our case, we can change the class path to junit.jar:., and choose "Build Application".
You'll notice that we didn't enter the name of the test suite being run. To add a parameter, select the Java Properties tag. You'll see that you can add properties to be set and modify many of the ones that you see. If you'd like, add the parameter junit.samples.AllTests and rebuild your application. In this case, we won't notice a real difference, but with other applications this will be useful.

The first community challenge: Jini
Perhaps the hardest thing about working with Jini is getting all of the pieces working on your machine. There are many sites that are devoted to long descriptions of the steps involved in getting rmid, a web server, Reggie, Mahalo, and Outrigger up and running.
Our first community challenge is to use the discussion forums on this page to come up with a very simple solution for running Jini on Mac OS X. You can find out more about Jini at Jini.org, and in Jini section of the Sun Microsystems web site. You can start up Jini with a GUI tool that comes with the distribution. To do this, just load the jini11_unix.properties file you will find in .../jini1_1/example/launcher/.
Daniel H. Steinberg is the editor for the new series of Mac Developer titles for the Pragmatic Programmers. He writes feature articles for Apple's ADC web site and is a regular contributor to Mac Devcenter. He has presented at Apple's Worldwide Developer Conference, MacWorld, MacHack and other Mac developer conferences.
Read more Java Programming on the Mac columns.
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 17 of 17.
-
MRJAppBuilder replaced by Jar Bundler
2003-07-22 04:12:35 anonymous2 [Reply | View]
-
MRJAppBuilder replaced by Jar Bundler
2004-08-13 12:05:15 DJH [Reply | View]
I found the problem, and the solution.
The problem is that Jar Bundler ignores any manual edits you make to the Classpath entries on the "Classpath and Files" tab.
The solution: once Jar Bundler has generated your app bundle, open the app folder and edit Contents->Info.plist. Find the ClassPath XML and manually edit it to look like this:
<key>ClassPath</key>
<string>$JAVAROOT/junit.jar:.</string>
Save the Info.plist and re-launch your app. Should run just fine this time.
BTW, I also put junit.samples.AllTests as an argument to main rather than as a "parameter" property.
DJH
-
Inner Class Names Chopped Short
2002-04-11 09:49:27 macneil [Reply | View]
TheBlueMarlin said that problems running JUNit were caused by, "... some of the .class files for inner classes in the junit/Tests directory have been chopped short somehow." I recompiled as he/she suggested, and JUNit runs now. However, we could not recompile without access to the source code. We don't always have access to the source code.
This seems like a serious problem. Why/how are the names chopped short, and what can we do about it?
-
How to change icons ?
2002-01-24 08:19:27 mhadley [Reply | View]
OK I give up. I've created a new icon file, added it to the OSX tab and merge tabs but I always get a generic app icon instead of my new one.
Any ideas ?
Marc
-
Deploy Java Applications
2001-09-19 06:20:08 mauri [Reply | View]
Is there a possibility to build a Java Application with the MRJAppBuilder (project.app) and then pack this file to put it on the webpage.
I always loose the package information on the project.app file after unpacking the file. So it is not double-clickable any more!
Michael
-
Swing & Menu bars
2001-08-21 14:56:06 larucker [Reply | View]
" It would be nice if the JUnit menu appeared where Mac menus are supposed to appear, but we can live with this approximation"
That's easy - add the com.apple.macos.useScreenMenuBar property and set it to true
-
Class not found
2001-08-19 12:19:07 boscarol [Reply | View]
When I write
java -cp /Users/mauro/Temi/Java/junit3.7/junit.jar:. junit.swingui.TestRunner junit.samples.AllTests
JUnit tells me that
Class not found "junit.samples.AllTests"
-
"failed to invoke" error message
2001-07-19 14:11:20 wt [Reply | View]
Hi...
After following the instructions, the application shows the following error message:
Failed to invoke suite():java.lang.NoClassDefFoundError: junit/tests/ExceptionTestCaseTest$ThrowRuntimeExceptionTestCase
Any help would be appreciated.
Thanks. -
"failed to invoke" error message
2001-11-01 16:02:52 thebluemarlin [Reply | View]
The cause of this problem is the way that some of the .class files for inner classes in the junit/Tests directory have been chopped short somehow. The simple solution is to recompile these classes.
Navigate to junit/tests and recompile the following java files.
1) RepeatedTestTest.java
2) TestImplementorTest.java
3) ExceptionTestCaseTest.java
4) ActiveTestTest.java
All 90 tests should now run.
TBM -
"failed to invoke" error message
2001-07-19 17:42:10 fikiri [Reply | View]
I also got the same message when following the instructions
Failed to invoke suite():java.lang.NoClassDefFoundError: junit/tests/ExceptionTestCaseTest$ThrowRuntimeExceptionTestCase
My best guess is this is a classpath problem but I also would like help is someone can be more specific. Could it be related to the fact I have junit on a separate volume from my home directory?
Fikiri -
"failed to invoke" error message
2001-07-21 11:42:05 Daniel H. Steinberg |
[Reply | View]
The problem comes from the last line before the return in the JUnit included sample code. Comment it out, recompile, live happily ever after.
More specifically, I am talking about the file "AllTests.java". Comment out the line,
suite.addTest(junit.tests.AllTests.suite());
Best,
Daniel
-
Stuffit wouldn't work for me
2001-07-08 10:23:47 canyonrat [Reply | View]
I couldn't get the project to run when I just let StuffIt unzip it. It kept saying that it couldn't find junit.samples.AllTests.
Using jar from within terminal worked fine though. -
Stuffit wouldn't work for me
2002-01-01 09:15:38 dieckmann [Reply | View]
When I used Stuffit it cuts the long names and JUnit could not find the class.
Jan Dieckmann -
Stuffit wouldn't work for me
2001-07-20 09:33:44 Daniel H. Steinberg |
[Reply | View]
Did you unzip it to the same directory specified in the jar description. I know, I probably should have been more specific.
Sorry,
Daniel






I am trying to run this code using Jar Bundler, the application that replaced MRJAppBuilder with the July 2003 Dev tools.
I just can't get the current directory defined in the classpath as in this article.
The application starts but can not find the class junit.samples.AllTests. I ran this example using the original MRJAppBuilder and everything worked fine, but with Jar bundler I can't get it to work - can anyone help ?
Max