Re: Java Tool with NSTask
Re: Java Tool with NSTask
- Subject: Re: Java Tool with NSTask
- From: Mijobe <email@hidden>
- Date: Mon, 26 Jan 2004 13:31:28 -0500
The first thing I would do is to write a wrapper class in Java to
handle the Java tool you want to interact with. A simple example might
be:
public class ToolWrapper {
protected ByteArrayOutputStream output = new ByteArrayOutputStream();
public void init() {
// Redirect System.out
System.setOut(new PrintStream(output));
... any other initialization.
}
public String getOutput() {
JavaTool.main(new String[0]);
return output.toString();
}
}
Then from your Objective C class you can do something like this:
- (NSString *)getOutput {
id clazz = NSClassFromString(@"example.JavaTool");
id javaTool = [[clazz alloc] init];
return [javaTool getOutput];
}
There are numerous configurations you need to make so that the JVM is
loaded and can find your java classes etc. Here's a good starting
point:
http://cocoadevcentral.com/articles/000024.php. I hope all that
helps.
-
email@hidden
<xinjen/>
On Jan 25, 2004, at 3:07 PM, Fabio Genoese wrote:
>
Hello,
>
>
Although I have solved the problem somehow (see my second mail today),
>
your idea sounds interesting. So yes: I wouldn't mind some example
>
code if you have some time!
>
>
thanks,
>
Fabio
>
>
>
>
>
You wrote:
>
>
Considering the ease of interoperating with Java applications unless
>
there's something stopping you I would execute the Java code myself.
>
For instance if the command line tool writes its output to System.out
>
the I would set System.out to an output stream that I could read from.
>
For instance if I remember correctly you can use a PipedOutputStream
>
connected to a PipedInputStream or a ByteArrayOutputStream and read
>
from that. Once you set System.out then simply call the main method on
>
the Java class and have it do its thing. If that doesn't make sense I
>
can provide you some example code.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.