Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / January 2006



Tip: Looking for answers? Try searching our database.

passing command line arguments from my app to a jar file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parchiba - 18 Jan 2006 21:01 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.