Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are there special requirements for invoking Java in a script controlled by launchd?



Greg Guerin wrote:
And I recommend NOT using a shell-script from an agent's plist file.  Just
enter the command-line args directly in your agent's plist file.  Otherwise
you have to think about controlling a shell that's controlling your app,
instead of just controlling your app.  Eliminate needless complication.


  
Thanks, this appears to have been my problem. I could tell the script process was stopping, but the java process continued to run. I don't know why I didn't think of just running the JVM from the plist file, and passing the parameters corresponding to the java command. In the plist file I originally had

k<key>ProgramArguments</key>
- <array>
         <string>/Applications/RemoteClipboard/RCBClient/startRCBClient</string>
</array>

where the contents of <string> is a pointer to my script file. The script file invokes the Java app, using java -cp my/classpath pkg.of.my.app.  Based on your recommendation, I replaced this with

<<key>ProgramArguments</key>
-     <array>
          <string>/System/Library/Frameworks/JavaVM.framework/Commands/java</string>
          <string>-cp</string>
          <string>/Applications/RemoteClipboard/RCBClient/lib/rcbClient.jar</string>
          <string>net.midnightjava.rcb.client.RCBInTray</string>
  </array>

and it works as desired. All I was trying to do was was use launchctl (I inadvertently said launchd in one place in my original post) to start and stop the daemon. I could tell the daemon was stopping and not restarting, by  looking at the console, and because with subsequent attempts to stop the daemon via "launchctl stop" the status returned indicated that the daemon was not running. So the daemon had stopped but the java app was still running, because I had the script between launchd and the java app, as you pointed out. Now I can enter "launchctl stop <joblabel>" and the java app stops. Then I enter
"launchctl start <joblabel>" and it starts again. I do not launch the app directly, I only control it via launchctl.

I had some trouble with the classpath arguments in the plist above, however. I originally had two classpaths in the third string element, separated by a ":", but the second classpath was not processed, as I got a NoClassDefFound error. Then I tried specifying each classpath as a separate  element, and also tried putting an element with a  ":" in between them, but none of these would work. I finally got it to work by putting the second classpath in the jar file rcbClient.jar. I should have done this to begin with, since it's an external library used by the code in the jar file, but I wonder why I wasn't able to get two classpaths working in the plist file. If I weren't launching the app from a jar file, I don't know how I would have made it work. Can someone post an example using two classpaths?

Also, can I expect the path to the java executable that I used above to work on every system when my app is distributed? I'll need to put the proper java executable path into the plist file during installation.

-Mark


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Are there special requirements for invoking Java in a script controlled by launchd? (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.