views:

412

answers:

3

We have a java app which we call with a parameter (a selected folder), which works fine in C#.

However, I'm at a loose end to work out how to do this in Objective-C; I've found the LaunchApplication command, but it's a bit vague.

Can someone please help me out?

A: 

Try using NSWorkspace:

[[NSWorkspace sharedWorkspace] openFile:@"~/Documents" withApplication:@"/Applications/MyApp.app"];

higgis
A: 

I've tried the following:

[[NSWorkspace sharedWorkspace] openFile:@"/Users/tharvey/Desktop/Test.jar" withApplication:@"/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java"];

Which throws an error in the console about being unable to start the java app and also:

 NSTask *javaApp = [[NSTask alloc] init];
 [javaApp setLaunchPath:@"/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java"];

 NSArray *javaAppArguments = [[NSArray alloc] init];
 javaAppArguments = [NSArray arrayWithObjects:@" -jar ", @"/Users/tharvey/Desktop/Test.jar", nil];
 [javaApp setArguments:javaAppArguments];

 [javaApp launch];

However the above code doesn't work; and doesn't throw an error.

Unless launching the jar will work on it's own?

Tom Harvey
This is not an answer to the question, so should not be here. Instead, modify your question to note that you've tried this.
Mike Abdullah
+2  A: 

As it's a Java app, not a document as such, you should be fine to do:

NSString *jarPath = @"/Users/tharvey/Desktop/Test.jar"
[[NSWorkspace sharedWorkspace] openFile:jarPath];

(Assuming the app can normally be launched by double-clicking in the Finder)

Mike Abdullah