Article ID: 000001
Last Revised On: 15-Sep-2005
PDF Version: 000001.pdf
The information in this article applies to:
This article applies to Excelsior JET versions 3.7 and earlier only. Since version 4.0, our product does not incorporate the JetPerfect feature and so it does not support creation of stand-alone DLLs.
The document contains step-by-step instructions on the use of Excelsior JET v3.7 for the creation of a standalone Java DLL and on calling that DLL from a C program. On the first few steps, a DLL dynamically linked with the JET runtime is created. The remaining steps show how to convert it to a standalone DLL.
Source files and build/run scripts for this article may be found here.
By default, JET links application code with the runtime dynamically, i.e. your classes are compiled and put into an executable (EXE or DLL) that requires one or more JET runtime DLLs containing precompiled Java 2 platform classes.
A standalone executable may be created with the help of Excelsior JET, Professional Edition feature — JetPerfect Global Optimizer. With JetPerfect, both application classes and required platform classes are compiled in one session. They are globally optimized and statically linked into a single executable (EXE or DLL) that does not need JET runtime DLLs and does not contain redundant code and data.
The use of JetPerfect gives you several important advantages:
Let’s consider the sample accompanying this article. First, you have to build a DLL in the default mode.
javac dllClass.java
jc =p =a dllClass.prj
or open dllClass.prj in the JET Control Panel and build it.
The source file main.c contains code that invokes dllClass methods using the standard Java Native Interface and Invocation API (http://java.sun.com/docs/books/jni/html/invoke.html).
Compile and link main.c with the xjvm.lib library that is part of your Excelsior JET installation:
cl -I%JDKDIR%\include\ -I%JDKDIR%\include\win32\ main.c %JETDIR%\lib\x86\xjvm.lib
(it is assumed that environment variables JDKDIR and JETDIR contain full paths to JDK and JET directories respectively.)
main.exe
Set the jet.usage.list and jet.default.classloader properties using the JETVMPROP environment variable and run the test application again to create the usage list:
SET JETVMPROP=-Djet.usage.list -Djet.default.classloader:application main.exe
As a result, the usage list will be automatically collected during execution and will be saved in a file with the application name and “.usg” extension. This example is very simple, but in complicated cases you may re-run your application as many times as you wish, supplying, for instance, different input data. The previously created .usg file will not be overwritten, but newly detected classes, methods and fields accessed via reflection will be added to it.
jc =p =a dllClass.prj -perfect+
It will take several minutes, because the required Java 2 platform classes will be compiled together with DLL classes.
cl -I%jdkdir%\include\ -I%jdkdir%\include\win32\ -DDynamicUseDLL main.c
main.exe
|
Home | Company | Products | Services | Resources | Blog | Contact | Request a Call Site: Search | Sitemap | Forum | Credits © 1999-2009 Excelsior LLC. All Rights Reserved. |