About the PC*MILER Connect Standalone JNI wrapper
Starting with PC*MILER Connect 28, we are offering all of the source code to our existing Connect Java wrapper.
The JNI layer is directly integrated with our PC*MILER Connect dll, pcmsrv32.dll. Older versions of the jar file or even new versions built with existing java code will still interface directly with pcmsrv32.dll (or pcmsrv64.dll). It is not mandatory to use this new stand alone JNI layer. If you are satisfied with the current behavior, then you can bypass the rest of this document.
There is now the option to build a separate JNI layer dll and interface with that instead. This is beneficial as it will allow users to expand the Java wrapper to gain access to any PC*MILER Connect APIs we do not currently expose through the Java wrapper. The instructions below cover the steps necessary to configure, build, and deploy everything necessary to do that.
There are two sets of code provided now. The native Java code used to build the traditional Java jar file and the C++ JNI layer used to create the JNI wrapper dll for our C-style APIs provided in pcmsrv32.dll. All of this code is architected using standard JNI practices.
To use the standalone JNI wrapper there is only one change needed in the Java code.
- Open up java/alk/connect/PCMSJava.java in an editor of your choice.
- Find the two System.loadLibrary() calls made at the top of the PCMSJava class. By default they reference the standard PC*Miler Connect dlls.
- We simply need to redirect them to point to the new standalone JNI wrapper dlls. The new names will be pcmsrv32_jni_wrapper and pcmsrv64_jni_wrapper. The screen shots below show the changes needed.
- Once these changes are made you can save and close PCMSJava.java. Navigate back to the Java.new root folder and run 01_build_jar.bat. The Java code will be recompiled and a new alk.jar will be put into the Java.new folder.
C++ JNI Wrapper
The jni_wrapper folder contains a MS Visual Studio 2005 project. If you're using a newer version of MS Visual Studio, simply open the solution file in the jni_wrapper folder and migrate it to your version of Visual Studio. Next, copy the pcmsrv32.lib + pcmsrv64.lib files from the Connect folder, which is stored within the PCMILER folder on your machine, and paste those files into the jni_wrapper folder. This will provide you with all of the necessary files and source code used to build a standalone JNI wrapper dll for our PC*MILER Connect product.
There are no code edits required to get it to work out of the box. You only need to edit the code if you want to expose new PC*MILER Connect APIs through the Java wrapper. If you are not doing that, you can just run 02_build_jni_wrapper.bat in the Java.new folder. Two dlls will be produced in the Java.new folder, pcmsrv32_jni_wrapper.dll and pcmsrv64_jni_wrapper.dll.
Once the two components are built deployment is very simple. As long as the PC*MILER Connect dll is accessible via a load library call the jar and jni wrapper dll can be put anywhere on the system. To verify this you can build and run our included PC*MILER Connect Java sample application. First you need to run 03_build_test.bat and then 04_run_test.bat to launch the test application.
The output of the test will be dumped to PCMSJavaTest_output.txt. If the test succeeded the output will contain a wide variety of API calls to calculate mileages, perform lookups, and run reports. (See attached reference guide for more information about the APIs.)