Is it possible to pass command-line arguments from a c program to
launch a jar file? This is what I am doing now:
LaunchTheJar( FSSpec* source){
StrFileName n = "\pTheJarToLaunch.jar";
FSRef r;
e = ::FSpMakeFSRef( source, &r );
LSLaunchFSRefSpec lSpec = {
&r, 0, nil, nil, kLSLaunchDefaults, nil
};
e = ::LSOpenFromRefSpec( &lSpec, NULL);
}
This works fine for launching, but I don't see any way of passing
arguments to the jar. A major problem (which I won't describe here) has
just arisen in a multiuser environment.
Anybody got any ideas?
Greg - 19 Jan 2006 00:44 GMT
All that launching the Jar file does is the equivalent of:
java -jar <myjar.jar>
All this does is run the jar's Main-Class attribute w/o any arguments,
just as executable jars are defined.
So, if you want to add parameters, you'll need to wrap the jar using
Apple's "Jar Bundler". With this tool you can specifiy the main class
and any command-line arguments needed.
parchiba - 19 Jan 2006 02:42 GMT
Okay, I get the Jar Bundler thing, sounds good. I will check that out.
Do you know offhand if it will be possible to change the arguments
before launching? What I need to do is check some system resources
(network ports) for availability, and then launch the jar with the
information (the port numbers to listen and talk on) about those
resources. So, the argumants may be different between launches.
Greg - 22 Jan 2006 02:32 GMT
Jar Bundler just runs the jar with the parameters supplied, it provides
no 'pre-processing' step.
I'd suggest that you write this wrapper in java (testing the ports,
etc) and then just call the main class in the original jar file with
the proper parameters.
-Greg