Java Application Process Name in Mac OS X
I have found that several of my Java applications have same process name on Mac OS X. JavaApplicationStub utility is usually used for launching java applications on mac os and as the result there are several processes named 'JavaApplicationStub' in Activity Monitor shown.
I have created simple HelloWorld application to reproduce this problem. And I was really surprised when saw that it's process name was correct!
Test application structure:
The process name in system:
I have realized that all needed to get correct process name is to define process name in project description Info.plist file (CFBundleName key):
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundleGetInfoString</key>
<string>HelloWorld swing application for Mac OS X</string>
<key>CFBundleIconFile</key>
<string>HelloWorld.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleName</key>
<string>HelloWorld</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>Java</key>
<dict>
<key>ClassPath</key>
<array>
<string>$JAVAROOT/HelloWorld-1.0-SNAPSHOT.jar</string>
</array>
<key>JVMVersion</key>
<string>1.5*</string>
<key>MainClass</key>
<string>com.kobyleha.HelloWorld.App</string>
<key>VMOptions</key>
<array>
<string>-Xms2M</string>
<string>-Xmx64M</string>
</array>
<key>WorkingDirectory</key>
<string>$APP_PACKAGE/Contents/Resources/</string>
</dict>
</dict>
</plist>
After reviewing my applications, I have found two reasons which can cause incorrect process name problems:
- Application uses SWT library for GUI building (in this case process name will be 'SWT')
- Application is hidden from doc and does not have GUI (you can do it by adding 'LSUIElement' key equals to '1' into Info.plist file)
It was quite easy to solve problem in SWT based applications. There is API method that can be used in your code to define correct process name exist. But keep in mind that you should call this method before Display creating and shell initialization (this was my problem reason):
public static void main(String[] args) {
Display.setAppName("HelloWorld");
display = new Display();
shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
...
}
I have found that in hidden application its process name depends on gui level initialization of the apple jvm. So only way to solve this problem is to create hidden unused frame:
public static void main(String[] args) {
JFrame f = new JFrame();
f.pack();
f.setVisible(false);
// Your hidden application code
f.dispose();
}
I hope this post would help someone. Comments are welcome!
| Attachment | Size |
|---|---|
| HelloWorld.app.zip | 36.95 KB |
»
- 1027 reads
- Russian