Then set up the myWOApp_main.m file to initialize the Java virtual machine and instantiate a Java class. Here is the standard implementation:
#import <JavaVM/NSJavaVirtualMachine.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Class JavaToolClass;
id javaToolObject;
// required for Solaris only to notify cthreads layer the main thread is being created
#if defined(__svr4__)
unsigned long java_reserved[16];
void cthread_set_java_vm_stack_base(void *);
cthread_set_java_vm_stack_base(java_reserved);
#endif
[NSBundle mainBundle]; //this initializes the JVM
JavaToolClass = NSClassFromString(@"Tool");
javaToolObject = [[JavaToolClass alloc] init];
NSLog (@"Java Tool Object = %@",javaToolObject);
[pool release];
exit(0); // insure the process exit status is 0
return 0; // ...and make main fit the ANSI spec.
}
The Java class Tool.java has been created. In this approach, Tool.java consists only of a constructor that instantiates another Java class, ToolImplementer.java here, which does the real work of this tool. After a ToolImplementer object is instantiated, execute one of its methods to start the tool working:
import java.lang.*;
public class Tool extends Object {
public Tool() {
super();
System.out.println("Creating a Tool instance");
ToolImplementer toolImplementer = new ToolImplementer();
toolImplementer.executeSomething();
System.out.println("toolImplementer.executeSomething() is executed");
System.exit(0);
}
}
Next, create the working class. The method "executeSomething" can of course be anything you want to begin accomplishing your tool's purpose:
import java.lang.*;
public class ToolImplementer extends Object {
public ToolImplementer() {
super();
System.out.println("Creating a ToolImplementer instance");
}
public void executeSomething() {
System.out.println("This is a ToolImplementer instance method");
}
}
Finally, create any other Java classes that you need for your tool. And that's all there is to it!