This topic applies to Java version only
Note: This will not work with JDK1.1.
If classes of an existing application are to be instrumented when they are loaded, a special ClassLoader needs to be used to run your application,com.db4o.nativequery.main.Db4oEnhancingClassLoader. Again db4o-x.x-nqopt.jar and bloat-1.0.jar need to be in the CLASSPATH.
All the native query code of your application would need to run in this ClassLoader. If we assume that you have a static starting method "goNative" in a class named "my.StarterClass", here is how you could run this method within the special native query ClassLoader:
01public static void enhancedLoader(){ 02
ClassLoader loader= 03
new com.db4o.nativequery.main.Db4oEnhancingClassloader(System.class.getClassLoader()); 04
try { 05
Class clazz=loader.loadClass("ApplicationExample"); 06
Method method=clazz.getMethod("run",new Class[]{}); 07
// invoke static method to start the app 08
method.invoke(null,new Object[]{}); 09
} catch (Exception ex){ 10
System.out.println(ex.getMessage()); 11
} 12
}
To start a full application in optimized mode, you can use the Db4oRunner utility class. If you would normally start your application like this:
$> java my.StarterClass some arguments
start Db4oRunner with the fully qualified name of your main class as the first argument and the actual arguments appended:
$> java com.db4o.nativequery.main.Db4oRunner my.StarterClass some arguments
Further options: