Category: Java/C++ Runtime
How do I deploy a mixed C++/Java application?
In our default in-process mode, the application will need access to the underlying Java classes and a Java runtime environment. While the runtime is capable of finding and using an installed JRE, you might wish to install your own JRE as part of your application. This guarantees that your users don't have to download and install anything other than your application and that they are always using the correct version of Java. This approach is sometimes called "using a private JRE" and its only downside is the potentially significant increase in the size of your application's disk image, something that is less and less of an issue in the days of terabyte hard drives.
Our customers (and we) have achieved excellent results with the application layout shown in the image to the right. This layout is by no means "the required layout" or even "the best way to do it," but it has some nice characteristics. Assuming that your application can be deployed in one application folder, this layout is well organized and is totally self-contained. As a result, your integrated application is xcopy-deployable, i.e. it can be copied from one folder to another and it will still work without any reconfiguration.
The bin directory contains the application executable, all the DLLs or shared objects, and optionally the co-located configuration file. The lib directory contains all required Java classes and properties files, usually packaged as jar files. The jre directory contains a Java runtime environment.
On Unix/Linux you only need to take care to deploy the proper runtime library for the compiler that you are using to build your application. Some Unixes might not allow you to deploy a private JRE because they expect Java to be in a well-defined location. Such requirements have a way to change with time, so we don't want to "enshrine" such information here. In MacOS-X for example, the JRE used to be an inseparable part of the OS and you could not have multiple different versions of Java at all. This has changed with the advent of MacOS-X 10.4. Regardless, if you need to deploy on such an OS, you should know the location of the JRE and you can special case this knowledge in your application.
As long as you are using relative paths in the runtime configuration, your application will work anywhere without requiring changes to the configuration. The following snippet shows the explicit configuration code that would be used in your application to work with the above layout:
xmog_jvm_loader & loader = xmog_jvm_loader::get_jvm_loader(); loader.appendToClassPath( "../lib" ); loader.appendToClassPath( "../lib/myapi.jar" ); loader.appendToClassPath( "../lib/myutil.jar" ); loader.setJvmPath( "../jre/bin/server/jvm.dll" );