JavaToDPR is a Java class that produces a Delphi project file from native methods declared in a Java class file. The project file compiles to a DLL which is used by Java to interact via the Java Native Interface (JNI.)
Download package Includes Delphi source. (~27 KB)
Sample usage
JavaToDPR [ options ] classnameExamples:java JavaToDPR HelloWorld java JavaToDPR -o HelloWorldImpl.dpr HelloWorld java JavaToDPR -platform Linux -o HelloWorldImpl.dpr HelloWorld java JavaToDPR java.lang.Object
JavaToDPR generates a Delphi DLL (library) project file. The generated project file will compile to a DLL that can be called from a Java class. The generated project file contains stubs of the native methods that need to be implemented in the Delphi DLL.By default, the output is sent to stdout (the console.) To save the output to a file, simply redirect the output to a file or use the -o <file> command-line switch to direct the output to a file. Once a project file has been generated, the programmer must implement the method stubs.
- -o outputfile
- Sends the output to outputfile. The previous contents of outputfile are discarded.
- -verbose
- Indicates verbose output and causes JavaToDPR to print the current search path (CLASSPATH) to stdout.
- -version
- Print out the version.
- -all
- Includes non-native methods in the output. By default, only native methods are included since that's the point of the tool. However, generating stubs for all methods is used as an internal debug and testing tool and may be useful in the future.
- -help
- Print out this information.
- -platform platform
- Indicates the platform the DLL will be compiled under. There are currently three supported values for platform:
Linux - Generates code for shared libraries under Linux. e.g. cdecl
- Win32 - Generates code for DLLs under Win32. e.g. stdcall
- All - Generates code for all platforms. e.g. {$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
- CLASSPATH
- Used to provide the system a path to user-defined classes. Directories are separated by colons under Linux and semi-colons under Win32, for example,
.:/home/jfk/classes:/usr/local/java/classes .;C:\Winnt\Java\classes;D:\JDK1.3\Classes
- Unlike javah, the C/C++ version from Sun which generates code for methods as well as fields of a Java class, JavaToDPR only generates stub code for methods.
- Overloaded methods generate duplicate entries in the exports section of the Delphi project file because the parameter list is not included in the export entry. You must manually copy the parameter list from the method stub to the exported function entry and then supply a name for the alias under which it will be exported. Also, you need to add the overload keyword to the methods that were generated. (This will be fixed in a future version.)
- Note that JavaToDPR is not a general Java to Delphi translator. It simply extracts the native method declarations from a Java class file and maps them to their equivalent Object Pascal declarations.
Using the Java Native Interface with Delphi
Setting the CLASSPATH on Linux
Setting the CLASSPATH on Windows
How classes are found
JDK Development Tools