Snippet #56
Language: Objective-C, Author: Michele Balistreri
License: Public domain
This code allows to start a Java Virtual Machine inside an application avoiding crashes which may be caused by having classpath items containing the ":" character in their paths, which is also classpath separator character (and Mac OS X way of storing the / character for file names). If you aren't sure that your application won't be placed in a path containing that character somewhere, this little hacks allows you to only write the name of the jars you wish to include in the classpath by telling it where to find them beforehand. basePath is the directory where those as stored which is most likely computed at runtime (for example by asking NSBundle) and may contain the problematic character.
void JVMM_SafeStart(NSString *basePath, NSString *classpath) { char buf[MAXPATHLEN]; getcwd(buf, MAXPATHLEN); NSString *javaPath = basePath; chdir([javaPath UTF8String]); //Initialize your JVM passing the classpath which should contain only colon-separated jar file names chdir(buf); }
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel
