Category: Java/C++ Runtime

Q

Is the system CLASSPATH used by my mixed Java/C++ application?

A

No. It's simply too dangerous to rely on the correct setup of the system classpath. Most production-quality Java applications configure their classpath in a startup script or batchfile. We did not want to force you to do this and consequently gave you have many ways to configure the classpath used by your C++ application, but if you're set on using the CLASSPATH, there are two ways you can do it.

The first option involves using a framework-recognized environment variable called XMOG_CLASSPATH. Simply set XMOG_CLASSPATH to the value of CLASSPATH and initialize your application so that it accepts environment variable overrides. The following snippet shows how to do this:

xmog_jvm_loader & loader = xmog_jvm_loader::get_jvm_loader( true, ... ) 

The key is to pass true as the first argument to the JVM loader factory method. This tells the runtime library that it should analyze the environment to look for variables that provide runtime settings. Please don't rely on a globally set XMOG_CLASSPATH environment variable. If you ever deploy more than one application that uses proxy classes and the two applications have conflicting classpath requirements, you're going to break one of them.

The second option involves simply doing it in code. There's nothing preventing you from reading the value of CLASSPATH in your application and using its value as an initialization argument. The following snippet illustrates this approach:

xmog_jvm_loader & loader = xmog_jvm_loader::get_jvm_loader();
const char *      cp = getenv( "CLASSPATH" );
 
if( cp != NULL )
    loader.setClassPath( cp );

As you can see, you can easily write your own initialization logic using a combination of built-in and custom techniques.


Copyright 2006-2011 by Codemesh, Inc., ALL RIGHTS RESERVED

:
frequently asked questions
home products support customers partners newsroom about us contact us