Accessing Java from ASP in Native Mode |
This example demonstrates how to access the Java from ASP in Native Mode. J-Integra® for COM is a Java interoperability component that bridges Java and ASPs. It provides bi-directional access of Java objects and COM components.
This example shows how to access a simple Java class from ASP using J-Integra® in native mode.
In this example you will modify the Accessing a Simple Java Class from Active Server Pages to take advantage of J-Integra®'s native mode, which loads the JVM either out-process or in-process into the ASP environment. Just like DCOM mode, you can access all public fields and methods (including static ones) in Java objects, without modifying the Java classes:
When using native mode with ASP, the JVM must be installed on the same machine as the ASP server. You can find more information about J-Integra®'s native mode in the Introduction to J-Integra® Native Mode.
Run the Accessing a Simple Java Class from Active Server Pages example, as this example reuses the code demonstrated there.
You are going to change the registration of the JVM on the ASP machine so that rather than being accessed via DCOM, it is accessed via native code out-process.
First, un-register the existing definition (which uses DCOM mode) using the regjvmcmd command in the d:\jintegra\bin directory:
> regjvmcmd /unregister aspjvm
Next, re-register it in native mode out-process:
> regjvmcmd /native aspjvm
The first parameter, /native, tells the regjvmcmd command that the JVM is to be accessed via native code out-process by default.
The second parameter, aspjvm, is the name
of the JVM (just like DCOM mode).
Alternatively you can run the regjvm.exe GUI tool to register the JVM:
Run the DCOMBridge program in native mode:
> set PATH=%PATH%;C:\jintegra\bin
> set CLASSPATH=%CLASSPATH%;.;C:\jintegra\lib\jintegra.jar
> javac DCOMBridgeJvm.java
> java -DJINTEGRA_NATIVE_MODE DCOMBridgeJvm
Restart your IIS:
When you access the ASP page you should see the Values output as follows:
You are going to change the registration of the JVM on the ASP machine so that rather than being accessed via DCOM, it is accessed via native code in-process.
First, un-register the existing definition (which uses DCOM mode) using the regjvmcmd command in the d:\jintegra\bin directory:
> regjvmcmd /unregister aspjvm
Next, re-register it in native mode in-process:
> regjvmcmd /native /inproc aspjvm
D:\jintegra\lib\jintegra.jar;d:\jintegra\lib;d:\pure
D:\jdk1.3.1\jre\bin\classic\jvm.dll DCOMBridgeJvm
The first parameter, /native, tells the regjvmcmd command that the JVM is to be accessed via native code.
The second parameter, /inproc, tells the regjvmcmd command that the JVM is to be loaded in-process into the COM client's address space.
The third parameter, aspjvm, is the name of the JVM (just like DCOM mode).
The fourth parameter, d:\jintegra\lib\jintegra.jar;d:\jintegra\lib;d:\pure, is the CLASSPATH to be used when the JVM is loaded. This must be set up to include the J-Integra® runtime (jintegra.jar) and all classes that you wish to access from ASP. In the above example I assume that DCOMBridgeJvm.class and DemoClass.class are in the D:\pure directory.
The fifth parameter, d:\jdk1.3.1\jre\bin\classic\jvm.dll, is the path to the JVM DLL associated with the JVM you wish to access. In the above example it is assumed that JDK1.3.1 is installed on your D:\ drive. The 'regjvmcmd' command will attempt to pick up the JVM dll automatically from your PATH if you leave out this parameter, but it is best to explicitly state it to be sure that the correct one is used.
The sixth parameter, DCOMBridgeJvm, is the name of a Java class that
contains a standard main. The J-Integra® runtime calls this main method
when the JVM is first loaded, to allow you to perform initialization.
This parameter can be omitted, in which case you won't have a chance
to perform any initialization, or to register JVMs with special properties
(for example, to intercept instantiation requests in order to access
CORBA objects or EJBs). Specify it when running this example so that
you can enable J-Integra® logging if it does not work at first.
Alternatively you can run the regjvm.exe GUI tool to register the JVM:
When using native mode in-process you do not need to run the DCOMBridge program.
Update your CLASSPATH at the System Variable level (Settings ->
Control Panel -> System -> Advanced -> Environment Variables... -> System
variables) to include the CLASSPATH of the Java class and jar files. Do NOT
update it
from User variables or command line.
Update your PATH at the System Variable level (Settings -> Control Panel -> System -> Advanced -> Environment Variables... -> System variables) to include the J-Integra® bin directory. Do NOT update it from User variables or command line.
Restart your IIS:
When you access the ASP page you should see the Values output as follows:
First check that the JVM is registered correctly. Ensure that the JVM DLL is correct, and that the CLASSPATH is correct. Use the 'regjvmcmd /list' command to see how it is registered.
If it still does not work, uncomment the Log.logImmediately(...) line in the DCOMBridgeJvm.java file, and change the log file to use an absolute file name ("c:\\temp\\jintegra.log"). Restart IIS/ASP and re-run the example, and see if the log file is created and if there are any obvious errors being reported.
If it still does not work, enable logging inside the J-Integra® moniker, by
creating a registry value (a string) called logFile with the value
c:\temp\jintmk.log
under the HKEY_LOCAL_MACHINE\SOFTWARE\Linar\JintMkr key.
Here is a screen capture showing what it should look like. Again restart IIS/ASP and try to access the ASP page and then look to see if a log has been created. Look through it for obvious errors.
If it still does not work, contact us including the jintegra.log (if it exists) generated by the J-Integra® runtime, the jintmk.log generated by the J-Integra® Moniker, and the checkconfig.log generated by doing checkconfig config.log.
Once you do have it working, please disable the logging by commenting the Log.logImmediately() line, and deleting the logFile registry entry.