ClassNotFoundException using JNI and JRE 6.0
I'm currently experiencing a problem with an application invoked by JNI that works under JRE 1.4 and 5.0, but not 6.0.
I wrote a standalone app that tests the lines of code in question and ran it from the command prompt using JRE 6.0 and it works ok.
This has lead me to believe that it has something to do with the JNI classloader as the class that it cannot find is on the classpath.
Any tips on things I might try?
Note: This app is also using classes from JavaMail and I have a similar thread open in that forum discussing some of the issues, but it seems to come back to the only difference between the working/non-working versions being JNI...
Thanks.
I'm currently experiencing a problem with an application invoked by JNI that works under JRE 1.4 and 5.0, but not 6.0.
I wrote a standalone app that tests the lines of code in question and ran it from the command prompt using JRE 6.0 and it works ok.
This has lead me to believe that it has something to do with the JNI classloader as the class that it cannot find is on the classpath.
Any tips on things I might try?
Note: This app is also using classes from JavaMail and I have a similar thread open in that forum discussing some of the issues, but it seems to come back to the only difference between the working/non-working versions being JNI...
Thanks.
Similar Messages
-
JVM Crash When Using JNI and COM
I'm trying to call a DLL compiled from VB6 source code that I do not have access to. The VB6 code simply retrieves data from a DB2 database using ADO and my client code grabs that data and marshals it to my Java code. I'm attempting to achieve this using JNI and COM (without a third-party bridge). It works 75% of the time, but the other 25% of the time, the JVM crashes with the usual Hotspot crash log containing an access violation exception. However, I don't know what in my C++ code (VC++ 8) could be causing this except for passing a "wild" pointer to the code lying underneath the COM object interface. If that is the case, I don't know how I am doing that.
The Java code that is calling my native method is running on Tomcat 5.5.25 and just to be safe, I am not allowing multiple threads to concurrently call the method in my JNI DLL (though I realize that this will kill performance). Once I can get past this problem, I'll do the COM interfacing on a worker thread in my native code so I don't screw up CoInitialize and CoUninitialize calls in the case the same thread is concurrently executing multiple calls to my native code.
I've noticed that in most cases, the JVM crashes during my call to the pClsAccount->OpenConnection method. However, my DLL isn't what is listed on the top of the call stack, which is why I suspect the passing of a wild pointer, though I'm just taking a guess at that. Does anyone have an idea as to what's going on ?
JNIEXPORT jobject JNICALL Java_CustomerInfo_nGetCustomerAccountInfo(JNIEnv *env, jobject customerInfo, jstring accountNumber, jstring iniFileName)
jboolean isCopy;
// Account info class and instance to be instantiated
jclass accountInfoCls = NULL;
jobject accountInfoObj = NULL;
// The constructor ID of the accountInfoCls
jmethodID ctorID = NULL;
// Pointer to the interface for the ClsAccount COM object
_clsAccount *pClsAccount = NULL;
HRESULT hr;
BSTR bstrIniFileName(L"");
try
const char *nativeAccountNumber = NULL;
if (accountNumber != NULL)
nativeAccountNumber = env->GetStringUTFChars(accountNumber, &isCopy);
else
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("java/lang/IllegalArgumentException");
env->ThrowNew(newExcCls, "accountNumber passed in was null !");
return NULL;
// Initialization
variantt varConnectionSucceeded = variantt(false);
variantt varGetAccountInfoSucceeded = variantt(false);
variantt varAccountNumber = variantt(nativeAccountNumber);
bstrt bstrLastPaymentDate = bstrt();
bstrt bstrLastErrorMessage = bstrt();
bstrt bstrLastErrorNumber = bstrt();
jlong jTotalDue = NULL;
jlong jEstablishedDueDay = NULL;
jlong jLastPaymentAmount = NULL;
jstring jLastPaymentDate = NULL;
jstring jLastErrorMessage = NULL;
jstring jLastErrorNumber = NULL;
jthrowable jException = NULL;
const char *chLastPaymentDate = NULL;
const char *chLastErrorMessage = NULL;
const char *chLastErrorNumber = NULL;
long long totalDue;
long long lastPaymentAmount;
long establishedDueDateDay;
//Convert string from Java string to C string to VB string
const char *nativeIniFileName = NULL;
if (iniFileName != NULL)
nativeIniFileName = env->GetStringUTFChars(iniFileName, &isCopy);
else
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("java/lang/IllegalArgumentException");
env->ThrowNew(newExcCls, "iniFileName passed in was null");
return NULL;
bstrIniFileName = comutil::ConvertStringToBSTR(nativeIniFileName);
CoInitialize(NULL);
// Create an instance of the COClass with the interface over it
hr = CoCreateInstance(__uuidof(clsAccount), NULL, CLSCTX_INPROC_SERVER, __uuidof(_clsAccount), (void **)&pClsAccount);
if (hr == S_OK)
varConnectionSucceeded.boolVal = pClsAccount->OpenConnection(&bstrIniFileName);
 
if (varConnectionSucceeded.boolVal == -1)
varGetAccountInfoSucceeded.boolVal = pClsAccount->GetAccountPaymentInformation(&(varAccountNumber.GetVARIANT()));
env->ReleaseStringUTFChars(accountNumber, nativeAccountNumber);
// Extract all available account information from the ClsAccount object
if (varGetAccountInfoSucceeded.boolVal == -1)
totalDue = pClsAccount->TotalDue.int64;
establishedDueDateDay = pClsAccount->EstablishedDueDateDay;
lastPaymentAmount = pClsAccount->LastPaymentAmount.int64;
bstrLastPaymentDate = pClsAccount->LastPaymentDate;
chLastPaymentDate = comutil::ConvertBSTRToString(bstrLastPaymentDate.GetBSTR());
jTotalDue = (jlong)totalDue;
jEstablishedDueDay = (jlong)establishedDueDateDay;
jLastPaymentAmount = (jlong)lastPaymentAmount;
jLastPaymentDate = env->NewStringUTF(chLastPaymentDate);
delete[] chLastPaymentDate;
pClsAccount->CloseConnection();
// Populate error fields if any errors occur
bstrLastErrorMessage = pClsAccount->LastErrMessage;
chLastErrorMessage = comutil::ConvertBSTRToString(bstrLastErrorMessage.GetBSTR());
bstrLastErrorNumber = pClsAccount->LastErrNumber;
chLastErrorNumber = comutil::ConvertBSTRToString(bstrLastErrorNumber.GetBSTR());
jLastErrorMessage = env->NewStringUTF(chLastErrorMessage);
jLastErrorNumber = env->NewStringUTF(chLastErrorNumber);
delete[] chLastErrorMessage;
delete[] chLastErrorNumber;
const char* clsName = "com/nuance/merchantsmutual/businessentities/CustomerAccountInfo";
// Find the Java class and the ID of its constructor
accountInfoCls = env->FindClass(clsName);
ctorID = env->GetMethodID(accountInfoCls, "<init>", "(JJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
jException = env->ExceptionOccurred();
if (jException != NULL)
env->ExceptionDescribe();
env->ExceptionClear();
//Release all resources associated with the ClsAccount instance
pClsAccount->Release();
//Instantiate the class with the given parameters
accountInfoObj = env->NewObject(accountInfoCls, ctorID, jTotalDue, jEstablishedDueDay, jLastPaymentAmount, jLastPaymentDate, jLastErrorMessage, jLastErrorNumber);
jException = env->ExceptionOccurred();
if (jException != NULL)
env->ExceptionDescribe();
env->ExceptionClear();
else if (hr == REGDB_E_CLASSNOTREG)
cout << "COM class not registered" << endl;
else if ( hr == CLASS_E_NOAGGREGATION)
cout << "COM class can't be aggregated" << endl;
else if (hr == E_NOINTERFACE)
cout << "No interface for COM class clsAccount" << endl;
else if (hr == E_POINTER)
cout << "*ppv pointer was NULL !" << endl;
else
cout << "Error occurred while creating COM object. HR is [" << hr << "]" << endl;
// Free the BSTR because a new one was returned with a call to comutil::ConvertStringToBSTR
SysFreeString(bstrIniFileName);
// Release the string when it's no longer needed. MUST call if string won't be used
// anymore or else a memory leak will occur
env->ReleaseStringUTFChars(iniFileName, nativeIniFileName);
CoUninitialize();
 
catch (_com_error &e)
cout << "Encountered an exception in GetCustomerAccountInfo: Error was " << e.ErrorMessage();
pClsAccount->Release();
catch (...)
pClsAccount->Release();
return accountInfoObj;
Edited by: Cthulhu76 on Jan 5, 2010 9:18 AM0x49202400 JavaThread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon [_thread_blocked, id=5340, stack(0x49bf0000,0x49c40000)]
0x48a7e800 JavaThread "Thread-1" [_thread_in_native, id=5976, stack(0x48f00000,0x48f50000)]
0x48a0dc00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3072, stack(0x48c60000,0x48cb0000)]
0x48a09000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4988, stack(0x48c10000,0x48c60000)]
0x48a07c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=3124, stack(0x48bc0000,0x48c10000)]
0x48a07000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2572, stack(0x48b70000,0x48bc0000)]
0x489f5c00 JavaThread "Finalizer" daemon [_thread_blocked, id=5752, stack(0x48b20000,0x48b70000)]
0x489f4c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=2596, stack(0x48ad0000,0x48b20000)]
0x003c6000 JavaThread "main" [_thread_in_native, id=4252, stack(0x00820000,0x00870000)]
Other Threads:
0x489f0400 VMThread [stack: 0x48a80000,0x48ad0000] [id=5624]
0x48a18800 WatcherThread [stack: 0x48cb0000,0x48d00000] [id=1192]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 36288K, used 12762K [0x02940000, 0x050a0000, 0x07800000)
eden space 32256K, 34% used [0x02940000, 0x0343af58, 0x048c0000)
from space 4032K, 37% used [0x04cb0000, 0x04e2ba28, 0x050a0000)
to space 4032K, 0% used [0x048c0000, 0x048c0000, 0x04cb0000)
tenured generation total 483968K, used 7518K [0x07800000, 0x250a0000, 0x42940000)
the space 483968K, 1% used [0x07800000, 0x07f57958, 0x07f57a00, 0x250a0000)
compacting perm gen total 14080K, used 14016K [0x42940000, 0x43700000, 0x46940000)
the space 14080K, 99% used [0x42940000, 0x436f0320, 0x436f0400, 0x43700000)
No shared spaces configured.
Dynamic libraries:
0x00400000 - 0x0040f000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\tomcat5.exe
0x7c800000 - 0x7c8c0000 C:\WINDOWS\system32\ntdll.dll
0x77e40000 - 0x77f42000 C:\WINDOWS\system32\kernel32.dll
0x77380000 - 0x77411000 C:\WINDOWS\system32\USER32.dll
0x77c00000 - 0x77c48000 C:\WINDOWS\system32\GDI32.dll
0x77f50000 - 0x77feb000 C:\WINDOWS\system32\ADVAPI32.dll
0x77c50000 - 0x77cef000 C:\WINDOWS\system32\RPCRT4.dll
0x76f50000 - 0x76f63000 C:\WINDOWS\system32\Secur32.dll
0x77ba0000 - 0x77bfa000 C:\WINDOWS\system32\MSVCRT.dll
0x7c8d0000 - 0x7d0cf000 C:\WINDOWS\system32\SHELL32.dll
0x77da0000 - 0x77df2000 C:\WINDOWS\system32\SHLWAPI.dll
0x76290000 - 0x762ad000 C:\WINDOWS\system32\IMM32.DLL
0x77420000 - 0x77523000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.3790.3959_x-ww_D8713E55\comctl32.dll
0x6d7c0000 - 0x6da10000 C:\Program Files\Java\jre1.6.0_07\bin\client\jvm.dll
0x76aa0000 - 0x76acd000 C:\WINDOWS\system32\WINMM.dll
0x7c340000 - 0x7c396000 C:\WINDOWS\system32\MSVCR71.dll
0x6d270000 - 0x6d278000 C:\Program Files\Java\jre1.6.0_07\bin\hpi.dll
0x76b70000 - 0x76b7b000 C:\WINDOWS\system32\PSAPI.DLL
0x6d770000 - 0x6d77c000 C:\Program Files\Java\jre1.6.0_07\bin\verify.dll
0x6d310000 - 0x6d32f000 C:\Program Files\Java\jre1.6.0_07\bin\java.dll
0x6d7b0000 - 0x6d7bf000 C:\Program Files\Java\jre1.6.0_07\bin\zip.dll
0x6d570000 - 0x6d583000 C:\Program Files\Java\jre1.6.0_07\bin\net.dll
0x71c00000 - 0x71c17000 C:\WINDOWS\system32\WS2_32.dll
0x71bf0000 - 0x71bf8000 C:\WINDOWS\system32\WS2HELP.dll
0x71b20000 - 0x71b61000 C:\WINDOWS\system32\mswsock.dll
0x5f270000 - 0x5f2ca000 C:\WINDOWS\system32\hnetcfg.dll
0x71ae0000 - 0x71ae8000 C:\WINDOWS\System32\wshtcpip.dll
0x76ed0000 - 0x76efa000 C:\WINDOWS\system32\DNSAPI.dll
0x76f70000 - 0x76f77000 C:\WINDOWS\System32\winrnr.dll
0x76f10000 - 0x76f3e000 C:\WINDOWS\system32\WLDAP32.dll
0x76f80000 - 0x76f85000 C:\WINDOWS\system32\rasadhlp.dll
0x4a6a0000 - 0x4a6ac000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\CustomerInfoProxy.dll
0x77670000 - 0x777a9000 C:\WINDOWS\system32\ole32.dll
0x77d00000 - 0x77d8b000 C:\WINDOWS\system32\OLEAUT32.dll
0x7c420000 - 0x7c4a7000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCP80.dll
0x78130000 - 0x781cb000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCR80.dll
0x777b0000 - 0x77833000 C:\WINDOWS\system32\CLBCatQ.DLL
0x77010000 - 0x770d6000 C:\WINDOWS\system32\COMRes.dll
0x77b90000 - 0x77b98000 C:\WINDOWS\system32\VERSION.dll
0x75da0000 - 0x75e5d000 C:\WINDOWS\system32\SXS.DLL
0x75e60000 - 0x75e87000 C:\WINDOWS\system32\apphelp.dll
0x4dc30000 - 0x4dc5e000 C:\WINDOWS\system32\msctfime.ime
0x4b0d0000 - 0x4b395000 C:\WINDOWS\system32\xpsp2res.dll
0x71bb0000 - 0x71bb9000 C:\WINDOWS\system32\WSOCK32.dll
0x4bbe0000 - 0x4bbea000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\ClearTranProxy.dll
0x745e0000 - 0x7489e000 C:\WINDOWS\system32\msi.dll
0x71c40000 - 0x71c97000 C:\WINDOWS\system32\NETAPI32.dll
0x4bc50000 - 0x4bc6c000 C:\WINDOWS\system32\DBNETLIB.DLL
0x71f60000 - 0x71f64000 C:\WINDOWS\system32\security.dll
0x76c90000 - 0x76cb7000 C:\WINDOWS\system32\msv1_0.dll
0x76cf0000 - 0x76d0a000 C:\WINDOWS\system32\iphlpapi.dll
0x761b0000 - 0x76243000 C:\WINDOWS\system32\crypt32.dll
0x76190000 - 0x761a2000 C:\WINDOWS\system32\MSASN1.dll
0x4bcf0000 - 0x4bcff000 C:\Program Files\Common Files\System\Ole DB\SQLOLEDB.RLL
0x4a8a0000 - 0x4a8aa000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MIGI.DLL
0x73570000 - 0x736c2000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MSVBVM60.DLL
0x4a950000 - 0x4a9e2000 C:\Program Files\Common Files\System\ado\msado15.dll
0x74a50000 - 0x74a6a000 C:\WINDOWS\system32\MSDART.DLL
0x4c850000 - 0x4c8c9000 C:\Program Files\Common Files\System\Ole DB\oledb32.dll
0x4dbb0000 - 0x4dbc1000 C:\Program Files\Common Files\System\Ole DB\OLEDB32R.DLL
VM Arguments:
jvm_args: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 5.5\temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\logging.properties -Djava.library.path=C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib vfprintf -Xms512m -Xmx1024m
java_command: <unknown>
Launcher Type: generic
Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_07
[error occurred during error reporting (printing environment variables), id 0xc0000005]
--------------- S Y S T E M ---------------
OS: Windows Server 2003 family Build 3790 Service Pack 2
CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 7 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3
Memory: 4k page, physical 2097151k(2097151k free), swap 4194303k(4194303k free)
vm_info: Java HotSpot(TM) Client VM (10.0-b23) for windows-x86 JRE (1.6.0_07-b06), built on Jun 10 2008 01:14:11 by "java_re" with MS VC++ 7.1
time: Mon Dec 28 15:24:00 2009
elapsed time: 600 seconds -
JRE 1.4.2_10 Silent install using MSi and JRE 5.0_06
I have been unable to install JRE 1.4.2_10 using the msi and mst silently. My company requires all applications be installed using and msi not an exe. and with no user intervention. I can install using the msi and mst but not silently,.
Also it does not allow me to choose IE as the default browser. I change the setting in the MST for IE, but this does not work, I still have to manually go in and change it after the install.
I have the same issue with version 5.0_06. This does allow me to choose IE as the default browser but does not install silently.
I am installing on Windows 2000 SP4.Can't help you with the MSI/MST part of your question directly, however we use the following command line:
jre-1_5_0_04-windows-i586-p.exe /s /v" /qn ADDLOCAL=jrecore,extra IEXPLORER=1 REBOOT=ReallySuppress JAVAUPDATE=0 SYSTRAY=0"
You might be able to make IEXPLORER=1 work for you via the MSI?
Additionally, you can manage JRE settings via the following method -
Place a file called 'deployment.config' in the following location:
%SystemRoot%\Sun\Java\Deployment
This file can act as a pointer to a configuration file (aka jre.properties)
The contents of 'deployment.config' would look like (as an example):
deployment.system.config=file://///servername/share/jre.properties
'jre.properties' would then contain this like:
deployment.version=1.5.0
deployment.browser.path=C\:\\Program Files\\Internet Explorer\\iexplore.exe
deployment.javaws.version=javaws-1.4.2_05
deployment.system.cachedir=C\:\\Temp\\Java\\cache
deployment.system.cachedir.locked
deployment.user.logdir=C\:\\WINNT\\Debug\\UserMode
deployment.user.logdir.locked
deployment.proxy.type=3
deployment.proxy.type.locked
deployment.cache.max.size=10m
deployment.cache.max.size.locked
deployment.trace=false
deployment.trace.locked
deployment.log=false
deployment.log.locked
deployment.javapi.lifecycle.exception=false
deployment.javapi.lifecycle.exception.locked
deployment.console.startup.mode=DISABLE
deployment.console.startup.mode.locked
deployment.browser.vm.iexplorer=true
deployment.browser.vm.iexplorer.locked
deployment.browser.vm.mozilla=false
deployment.browser.vm.mozilla.locked
deployment.javaws.shortcut=NEVER
deployment.javaws.shortcut.locked
deployment.javaws.associations=NEVER
deployment.javaws.associations.locked
deployment.security.askgrantdialog.show=true
deployment.security.askgrantdialog.show.locked
deployment.security.askgrantdialog.notinca=true
deployment.security.askgrantdialog.notinca.locked
deployment.security.browser.keystore.use=true
deployment.security.browser.keystore.use.locked
deployment.security.notinca.warning=false
deployment.security.notinca.warning.locked
deployment.security.expired.warning=false
deployment.security.expired.warning.locked
deployment.security.jsse.hostmismatch.warning=false
deployment.security.jsse.hostmismatch.warning.locked
deployment.security.sandbox.awtwarningwindow=false
deployment.security.sandbox.awtwarningwindow.locked
deployment.security.sandbox.jnlp.enhanced=false
deployment.security.sandbox.jnlp.enhanced.locked
deployment.system.tray.icon=false
deployment.system.tray.icon.locked
For more details:
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html>
This could help you as well? Good luck. -
Problems using JNI and JSP in WebLogic 6.0
Hello everybody. My problem is that I've got a Java class that is called from a JSP. That class connects to a C function and it returns a String. A want this string to be shown by the JSP. The code is:
JSP
<html>
<head>
<title>prueba JNI</title>
</head>
<body>
<%@ page import="ejemplosJNI.*, conversiones.*;"%>
<%
Texto texto = new Texto();
out.println(texto.realizado());
%>
</body>
</html>
Java class
package ejemplosJNI;
public class Texto
private native String getLine(String prompt);
String input = null;
public static void main(String args[])
Texto t = new Texto();
static
System.loadLibrary("MyImpOfPrompt");
public String realizado()
input = this.getLine("Mando una l�nea desde Java");
return input;
C function
#include <stdio.h>
#include <jni.h>
#include "Texto.h"
JNIEXPORT jstring JNICALL
Java_Texto_getLine(JNIEnv *env, jobject obj, jstring prompt)
char buf[128];
const char str = (env)->GetStringUTFChars(env, prompt, 0);
(*env)->ReleaseStringUTFChars(env, prompt, str);
return (*env)->NewStringUTF(env, str);
I compile de C function and put the .dll library in the 'bin' folder in webLogic.
When I call the JSP, I get the next exception:
Servlet failed with Exception
java.lang.UnsatisfiedLinkError: getLine
at ejemplosJNI.Texto.getLine(Native Method)
at ejemplosJNI.Texto.realizado(Texto.java:19)
at jsp_servlet._jsp._pruebasjni._prueba1._jspService(_prueba1.java:93)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:213)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:246)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:1265)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:1622)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
Is there any place where I have to put the .dll?
Is there any place where I have to put the generated .lib?
Where do I have to put the Texto.h file generated with javah?
Can anybody help me to solve this problem?
Thanks in advance.Hi, jschell! Maybe you can see my problem if I give you the code. My Java class and the C funtions are:
Java class
package ejemplos.cadena;
public class Texto
private native String getLine(String prompt) throws Exception;
String cadenaFinal = null;
public static void main(String args[])
Texto t = new Texto();
static
System.loadLibrary("LibreriaCadena");
public String realizado(String cadena)
try
cadenaFinal = getLine(cadena);
catch(Exception e)
System.out.println(e.toString());
return cadenaFinal;
C code
#include <stdio.h>
#include <jni.h>
#include "ejemplos_cadena_Texto.h"
JNIEXPORT jstring JNICALL
Java_ejemplos_cadena_Texto_getLine(JNIEnv *env, jobject obj, jstring prompt)
int cero =0;
int division = 10 / cero;
const char str = (env)->GetStringUTFChars(env, prompt, 0);
(*env)->ReleaseStringUTFChars(env, prompt, str);
return (*env)->NewStringUTF(env, str);
I have done something like "int division = 10 / cero;" in order to get an exception in my C code. When I run my Java class I get an error message and the application breaks. I would like to know how to catch the C exception in order to pass it to my Java class that can manage it into the try-catch clause. I have read I have to use something like "FindClass" or "ThrowNew", but my problem is that I have no idea about C programming.
Can you help me?
Thanks for your time. -
When using a DLL I'm supposed to use javah on my class file, for creation of a C headerfile. How's this done in JDeveloper?
JDeveloper doesn't include a wizard for this. You can run setvars.bat from the JDeveloper\Bin directory from a command prompt and that will set up your path and CLASSPATH for using the command line tools.
You can then run the javah command directly to generate the header files to use when creating your C/C++ JNI code.
Take Care,
Rob
null -
Updating java when using JDK and JRE
Ok, so after you make a program in java and compile it, you then install the new update of java. Wouldn't the virtual machine(JRE) or java development kit(JDK) notice something thats different and bring up an error?
Do you have to use the same JDK as JRE that you have, because if you didn't have the most updated one, wouldn't there come up with an error?
Last question, if you have used the command line to compile a program, then you know that you need to use javac to compile and java to run it. Well when you use the command javac to compile, then you are using the JDK; and if you use the java command to run it, then you are using JRE. This is just a question to make sure that I have this correct, So correct me if I'm wrong.brown16b wrote:
Ok, so after you make a program in java and compile it, you then install the new update of java. Wouldn't the virtual machine(JRE) or java development kit(JDK) notice something thats different and bring up an error? Why? A newer Java version should be able to execute programs compiler for a prior version.
Do you have to use the same JDK as JRE that you have, because if you didn't have the most updated one, wouldn't there come up with an error?Eh, what?
Last question, if you have used the command line to compile a program, then you know that you need to use javac to compile and java to run it. Well when you use the command javac to compile, then you are using the JDK; and if you use the java command to run it, then you are using JRE. This is just a question to make sure that I have this correct, So correct me if I'm wrong.It's correct. -
Java 1.5 JNI and C++ exception
Hello, All
I've troubles with handling C++ exceptions using JNI and shared library. I'm using Java 1.5_06, RedHat 7.3 and JBoss 4.0.5
From Java class I call JNI a method in my shared library(libx.so) which calls a method in other shared library(liby.so). Liby.so uses Xerces library. During parsing process an exception occurs. But according to Xerces sources it's a normal behavior and should be caught. But instead I've got SIGNABRT in JVM and a core dump will created. What's wrong? Backtrace shows similar something:
XXXXX __default_terminate() ....
XXXXX __terminate() ....
XXXXX __throws
XXXXX C++ method ..
XXXXX.....
XXXXX.....
XXXXX JNI methodI found similar bugs reports in the forum. But they says about Java 1.4 version and according to bugs descriptions it should be already fixed.
Message was edited by:
kostik78The question is closed. The root cause was incorrect building of shared library.
-
Hi,
This is the first time I use jni and I encountered some problem when trying to accessing instance fields. My source code is as follows:
java side:
class C {
int j;
private native void f();
static { System.loadLibrary("C"); }
public static void main(String[] args)
C c = new C();
c.j = 5;
System.out.println("Before calling: " + c.j);
c.f();
System.out.println("After calling: " + c.j);
native (c) side:
#include <stdio.h>
#include "C.h"
JNIEXPORT void JNICALL Java_C_f(JNIEnv *env, jobject obj)
jfieldID fid;
jclass cls = (*env)->GetObjectClass(env, obj);
fid = (*env)->GetFieldID(env, cls, "j", "I");
if (fid == 0) {
return;
printf("Before set: %d\n", (*env)->GetIntField(env, cls, fid));
(*env)->SetIntField(env, cls, fid, 100);
printf("After set: %d\n", (*env)->GetIntField(env, cls, fid));
The programs compile and run smoothly, but the result is not what I expect. Please see the result below:
jason1:~/jni/accessInstanceVar> make
javac C.java
javah -jni C
gcc \
-I/usr/lib/jdk1.1/include \
-I/usr/lib/jdk1.1/include/linux \
Java_C_f.c -c -o libC.o
gcc -shared -o libC.so libC.o
java C
Before calling: 5
Before set: 196653
After set: 100
After calling: 5
I don't know why the value of the instance variable is not 5 when first accessed in the native function and why it is still 5 after the native function returns.
Can someone help me? Thanks in advance!
YongIt looks to me like you try to set a value of an instance variable like a static varibale.
I think you need exatra information like the object which the instance variable like so:
(*env)->SetIntField(env, obj, fid, 100);;
instead of
(*env)->SetIntField(env, cls, fid, 100);
Hope this will help
Joeseph. -
hello,
I have just started using jni and I was based o this tutoriel http://www.netbeans.org/kb/55/beginning-jni-part1.html but always I GOT AN ERROR so if u can help me in it or can give another tutoriel to follow it
thankswhat's the error?
-
Application crashes when using JNI with Jdk 1,2, 1.3 and 1.4
Hi!
I have this application that has a GUI written in Java and a file parser written in C. JNI is used to connect these parts together. The problem is that the application only works when I am using jdk 1.1.8 but not when using jdk1.2, jdk1.3 or jdk1.4. I am running the application on a Solaris 8 machine.
I have not written the application myself but I am going to be working with it from now on. But I have today little knowledge with JNI and I have tried different approaches to solve the problem. For example I have tried to used DDD together with GDB to find out what the problem is but with no luck. When I run the application using jdk1.4 I get the following error when the JVM crashes:
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 10 occurred at PC=0xFA023164
Function=Java_Bitmap_setDebug+0x1C
Library=/usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
Current Java thread:
at Bitmap.setDebug(Native Method)
at DisplayPanel.loadFile(DisplayPanel.java:396)
at MicPlot.loadFile(MicPlot.java:1452)
at MicPlot.loadFile(MicPlot.java:1441)
at MicPlot.miOpen_Action(MicPlot.java:1267)
at MicPlot$SymAction.actionPerformed(MicPlot.java:1184)
at java.awt.MenuItem.processActionEvent(MenuItem.java:588)
at java.awt.MenuItem.processEvent(MenuItem.java:548)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Dynamic libraries:
0x10000 /opt/java/jdk1.4/bin/java
0xff360000 /usr/lib/libthread.so.1
0xff3a0000 /usr/lib/libdl.so.1
0xff280000 /usr/lib/libc.so.1
0xff270000 /usr/platform/SUNW,Ultra-4/lib/libc_psr.so.1
0xfe000000 /opt/java/j2sdk1.4.1/jre/lib/sparc/client/libjvm.so
0xff220000 /usr/lib/libCrun.so.1
0xff200000 /usr/lib/libsocket.so.1
0xff100000 /usr/lib/libnsl.so.1
0xff1d0000 /usr/lib/libm.so.1
0xff250000 /usr/lib/libw.so.1
0xff0e0000 /usr/lib/libmp.so.2
0xff0b0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/native_threads/libhpi.so
0xff080000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libverify.so
0xff030000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libjava.so
0xfe7e0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libzip.so
0xfe4e0000 /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.2
0xedd00000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libawt.so
0xfc480000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libmlib_image.so
0xfc410000 /opt/java/j2sdk1.4.1/jre/lib/sparc/motif21/libmawt.so
0xeda80000 /usr/dt/lib/libXm.so.4
0xfa090000 /usr/openwin/lib/libXt.so.4
0xfa3d0000 /usr/openwin/lib/libXext.so.0
0xfc7e0000 /usr/openwin/lib/libXtst.so.1
0xed980000 /usr/openwin/lib/libX11.so.4
0xfa2a0000 /usr/openwin/lib/libdps.so.5
0xfa3b0000 /usr/openwin/lib/libSM.so.6
0xfa1d0000 /usr/openwin/lib/libICE.so.6
0xed880000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libfontmanager.so
0xfa390000 /usr/openwin/lib/locale/common/xlibi18n.so.2
0xfa1b0000 /usr/openwin/lib/locale/iso8859-1/xomEuro.so.2
0xfa190000 /usr/lib//liblayout.so
0xfa050000 /usr/openwin/lib/locale/common/ximlocal.so.2
0xfa010000 /usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
Local Time = Thu Oct 3 13:32:47 2002
Elapsed Time = 35
# The exception above was detected in native code outside the VM
# Java VM: Java HotSpot(TM) Client VM (1.4.1-beta-b14 mixed mode)
# An error report file has been saved as hs_err_pid27692.log.
# Please refer to the file for further information.
Abort
From this information I think that the problem should be in the native method setDebug. But I have tried to set a breakpoint at the beginning of that function in the C part but with no luck. The application crashes before it reaches that position in the C file.
What could possibly go wrong between the setDebug function in the C part and the function call in the Java part?
When using GDB, GDB cannot figure out what is wrong it just returns a hex address, no function name.
I would really appreciate some help. I have tried everything that I can come up with!
Best regards
LarsI have figured out that the application fails on its first call to the native methods.
So I have this Bitmap class that contains all the native calls and it is defined shortly as follow:
public class Bitmap {
static {
System.loadLibrary("BitmapImpl");
native void setDebug(int debuglevel, int statistics);
There are many more native methods defined in Bitmap, but I only show the setDebug method because that is the first one that is executed and also the one that immediately fails.
My setDebug C function is defined as follow in BitmapImpl.c
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <fcntl.h>
#include <jni.h>
#include <math.h>
#include <errno.h>
#include "Bitmap.h"
#include "data.h"
jint debug = 0;
jint statistics = 1;
JNIEXPORT void JNICALL Java_Bitmap_setDebug
(JNIEnv *jenv, jobject jo, jint d, jint s)
debug = d;
statistics = s;
My libBitmapImpl.so file is compiled using the following Makefile and using GNU gcc:
JAVAPATH=$(JAVAINCLUDEPATH)
LMACRO=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DSOLARIS
CSOURCE=BitmapImpl.c
all:
gcc -O3 -G $(LMACRO) -I$(JAVAPATH) -I$(JAVAPATH)/solaris \
$(CSOURCE) -o libBitmapImpl.so
It is still a total mystory why the application fails. I have tried it on a RedHat Linux machine and there it works fine. But not on Solaris. Only if I use the jdk1.1.8 but not a later one.
Would really appreiciate some help!
Best regards
Lars -
My web page uses a Java Applet to allow my visitors to replay chess games; the Chess Viewer Deluxe applet was written by Nikolai Pilafov some time ago and has been working properly for some time (until recently). I don't monitor this part of my site regularly so I am not sure when it began to fail. On his web site [http://chesstuff.blogspot.com/2008/11/chess-viewer-deluxe.html] he has a link to check LiveConnect object functionality (which fails for OBJECT tags). His recommendation is to "seek platform specific support which might be available from the JRE developers for your platform".
I have been getting java.lang.ClassNotFoundException: ZeroApplet.class and java.lang.ClassNotFoundException: JavaToJS.class crashes with JRE version 1.6.0_26-b03-384-10M3425 VM executing a Java Applet. Until I checked the LiveConnect object functionality, I was unable to identify the source of the console error messages. This does seem to be the smoking gun.
Is Apple aware of this problem? Are these classes no longer supported? Has anyone else had this problem? You can attempt to recreate the problem locally by going to my web page: http://donsmallidge.com/DonSmallidgeChess.html
Thanks in advance for any help you can provide!
Abbreviated Java Console output:
Java Plug-in 1.6.0_26
Using JRE version 1.6.0_26-b03-384-10M3425 Java HotSpot(TM) 64-Bit Server VM
load: class ZeroApplet.class not found.
java.lang.ClassNotFoundException: ZeroApplet.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:680)
load: class JavaToJS.class not found.
java.lang.ClassNotFoundException: JavaToJS.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:680)I just went up to check the LiveConnect object functionality page AND IT WORKED THIS TIME! I must confess, this is very mysterious. I will do some more checking and reply here if I can determine why it is working now (and more importantly, why it didn't work before).
-
Deploying a WAR file containing .jsp and servlets (also uses JNI)
Deploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
Server documentation on deploying such files.
This is how we went about it:
1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
Server.
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
and
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
(We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
service packs)
From browser, open http://yourserver:8888/
Click on Select a Server:Manage
Click on Virtual Server Class
Click on https-yourserver
Click on the Web Applications Tab
Then, click on Deploy Web Application
Enter the following -
WAR File On: Local
WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Application URI: /jakarta
Installation Directory: c:\iPlanet\examples\jakarta-examples
By clicking on OK it deployed the application.
I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
Edit /jakarta c:/iPlanet/examples/jakarta-examples
Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
- [images]
- [jsp]
- index.html
- [servlets]
- [META-INF]
- [WEB-INF]
- [classes]
- [tlds]
- web.xml
- index.html
I restarted the server and accessed it using the following URL from my IE browser:
http://yourserver/jakarta/index.html
Then I clicked on the JSP Examples and tried some JSP examples.
b) Alternatively, you can also deploy the same example from the command-line.
Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
wdeploy deploy -u /jakarta
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\jakarta-examples
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Restart the web server (I don't think you have to restart, but .. might as well).
2)Deploy your web-application
My Foo.war has the following structure.
You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
in your PATH)
Foo.war
- [META-INF]
- [WEB-INF]
- web.xml
- [classes]
- Bar.class
- MoServlet.class
- [lib]
- ThirdParty.jar
- [natlib]
- extlib.dll
- foo.jsp
Here is our application scenario:
foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
Now to deploy it, do the following:
(a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
JSP compile error).
<%@page language="java" import="Bar" contentType="text/html"%>
(b) Check web.xml (for Servlets)
Within web.xml, make sure you have the following mappings:
<servlet>
<servlet-name> MoLink </servlet-name>
<servlet-class> MoServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> MoLink </servlet-name>
<url-pattern> /servlet/Mo </url-pattern>
</servlet-mapping>
(c) Deploy the application
Using command line:
wdeploy deploy -u /foo
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\foo-dir
Foo.war
(d) Change web-apps.xml file (for picking up ThirdParty.jar)
It is located in
C:\iPlanet\Servers\https-yourserver\config
You should see something similar to following after successful deployment.
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
Change it to look like following to pick up the ThirdParty.jar
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
<class-loader reload-interval="300"
classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
delegate="false"/>
</web-app>
(e) Change jvm12.conf file (for JNI)
It is located in
C:\iPlanet\Servers\https-yourserver\config
Add or uncomment the following lines:
#optional - just helps with instrumenting the jsp and servlet code
jvm.include.CLASSPATH=1
jvm.enableDebug=1
nes.jsp.enabledebug=1
jvm.trace=7
jvm.verboseMode=1
#required for JNI
java.compiler=NONE
jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
jvm.option=-Xrs
jvm.option=-Xnoagent
# not sure if this is needed for iPlanet web server
jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
(f) Change magnus.conf file (for JNI)
We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
in Path, it didn't work.
Change Extrapath directive:
ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
to
ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
(g) Apply changes from the Web Server Administration Console and Restart the web server.
You should be able to see the behaviour that you want from your application.
http://yourserver/foo/foo.jsp
Hope this was helpful!!!
SonuDeploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
Server documentation on deploying such files.
This is how we went about it:
1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
Server.
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
and
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
(We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
service packs)
From browser, open http://yourserver:8888/
Click on Select a Server:Manage
Click on Virtual Server Class
Click on https-yourserver
Click on the Web Applications Tab
Then, click on Deploy Web Application
Enter the following -
WAR File On: Local
WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Application URI: /jakarta
Installation Directory: c:\iPlanet\examples\jakarta-examples
By clicking on OK it deployed the application.
I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
Edit /jakarta c:/iPlanet/examples/jakarta-examples
Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
- [images]
- [jsp]
- index.html
- [servlets]
- [META-INF]
- [WEB-INF]
- [classes]
- [tlds]
- web.xml
- index.html
I restarted the server and accessed it using the following URL from my IE browser:
http://yourserver/jakarta/index.html
Then I clicked on the JSP Examples and tried some JSP examples.
b) Alternatively, you can also deploy the same example from the command-line.
Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
wdeploy deploy -u /jakarta
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\jakarta-examples
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Restart the web server (I don't think you have to restart, but .. might as well).
2)Deploy your web-application
My Foo.war has the following structure.
You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
in your PATH)
Foo.war
- [META-INF]
- [WEB-INF]
- web.xml
- [classes]
- Bar.class
- MoServlet.class
- [lib]
- ThirdParty.jar
- [natlib]
- extlib.dll
- foo.jsp
Here is our application scenario:
foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
Now to deploy it, do the following:
(a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
JSP compile error).
<%@page language="java" import="Bar" contentType="text/html"%>
(b) Check web.xml (for Servlets)
Within web.xml, make sure you have the following mappings:
<servlet>
<servlet-name> MoLink </servlet-name>
<servlet-class> MoServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> MoLink </servlet-name>
<url-pattern> /servlet/Mo </url-pattern>
</servlet-mapping>
(c) Deploy the application
Using command line:
wdeploy deploy -u /foo
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\foo-dir
Foo.war
(d) Change web-apps.xml file (for picking up ThirdParty.jar)
It is located in
C:\iPlanet\Servers\https-yourserver\config
You should see something similar to following after successful deployment.
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
Change it to look like following to pick up the ThirdParty.jar
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
<class-loader reload-interval="300"
classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
delegate="false"/>
</web-app>
(e) Change jvm12.conf file (for JNI)
It is located in
C:\iPlanet\Servers\https-yourserver\config
Add or uncomment the following lines:
#optional - just helps with instrumenting the jsp and servlet code
jvm.include.CLASSPATH=1
jvm.enableDebug=1
nes.jsp.enabledebug=1
jvm.trace=7
jvm.verboseMode=1
#required for JNI
java.compiler=NONE
jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
jvm.option=-Xrs
jvm.option=-Xnoagent
# not sure if this is needed for iPlanet web server
jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
(f) Change magnus.conf file (for JNI)
We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
in Path, it didn't work.
Change Extrapath directive:
ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
to
ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
(g) Apply changes from the Web Server Administration Console and Restart the web server.
You should be able to see the behaviour that you want from your application.
http://yourserver/foo/foo.jsp
Hope this was helpful!!!
Sonu -
How can WLS use JSP pages in a Web Application (either a .war file or a war directory structure) without a java compiler?
I suspect either the JSP specification is flawed (i.e. it doesn't take account of servers using just a JRE), or BEA's implementation is broken.
Production servers do not have a JDK installed. They only have a JRE. Therfore a java compiler is not present on the machine that the Web Application is deployed onto.
On the development machine, when the server is requested to load the JSP it creates a tmpwar directory within the Web Application directory structure. This is then included in the resultant .war file thus:
D:\war>jar -tf gmi.war
META-INF/
META-INF/MANIFEST.MF
gmiService.jsp
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
WEB-INF/classes/com/bt/
WEB-INF/classes/com/bt/gmi/
WEB-INF/classes/com/bt/gmi/gmiService.class
WEB-INF/getList.xsl
WEB-INF/getListByConnection.xsl
WEB-INF/getListByDistrict.xsl
WEB-INF/getListByDistrictConnection.xsl
WEB-INF/lib/
WEB-INF/source/
WEB-INF/source/build.bat
WEB-INF/source/gmiService.java
WEB-INF/web.xml
WEB-INF/weblogic.xml
tmpwar/
tmpwar/jsp_servlet/
tmpwar/jsp_servlet/_gmiservice.class
tmpwar/jsp_servlet/_gmiservice.java
When deployed on the production server with the web.xml file set to use the following values (note XML stripped):
weblogic.jsp.pageCheckSeconds
-1
weblogic.jsp.precompile
false
weblogic.jsp.compileCommand
javac
weblogic.jsp.verbose
true
weblogic.jsp.packagePrefix
jsp_servlet
weblogic.jsp.keepgenerated
false
And in the weblogic.properties file:
weblogic.httpd.webApp.gmi=war/gmi
I've also tried with the .war file, but that insists on creating another tmpwar directory outside of the .war file.
Then, although I have set pageCheckSeconds to -1 (don't check and don't recompile) ter production server still attempts to recompile the JSP's:
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: init
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param verbose initialized to: true
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param packagePrefix initialized to: jsp_servlet
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param compileCommand initialized to: javac
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param srcCompiler initialized to weblogic.jspc
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param superclass initialized to null
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param workingDir initialized to: /opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param pageCheckSeconds initialized to: -1
Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: initialization complete
Mon Sep 25 11:40:12 BST 2000:<I> <WebAppServletContext-gmi> Generated java file: /opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.java
Mon Sep 25 11:40:14 BST 2000:<E> <WebAppServletContext-gmi> Compilation of /opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.java failed: Exception in thread "main" java.lang.NoClassDefFoundError: sun/tools/javac/Main
java.io.IOException: Compiler failed executable.exec([Ljava.lang.String;[javac, -classpath, /opt/Solaris_JRE_1.2.1_04/lib/rt.jar:/opt/Solaris_JRE_1.2.1_04/lib/i18n.jar:/opt/Solaris_JRE_1.2.1_04/classes:/var/wls/5.1/weblogic/lib/weblogic510sp4boot.jar:/var/wls/5.1/weblogic/classes/boot:/var/wls/5.1/weblogic/eval/cloudscape/lib/cloudscape.jar:/var/wls/5.1/weblogic/lib/wleorb.jar:/var/wls/5.1/weblogic/lib/wlepool.jar:/var/wls/5.1/weblogic/lib/weblogic510sp4.jar:/var/wls/5.1/weblogic/license:/var/wls/5.1/weblogic/classes:/var/wls/5.1/weblogic/lib/weblogicaux.jar:/opt/wls-servers/gmiServer/weblogic/gmiServer/serverclasses:/opt/wls-servers/gmiServer/weblogic/lotusxsl.jar:/opt/wls-servers/gmiServer/weblogic/xerces.jar:/opt/wls-servers/gmiServer/weblogic/logging.jar::/opt/wls-servers/gmiServer/weblogic/war/gmi/WEB-INF/classes:/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war, -d, /opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war, /opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.java])
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at java.io.IOException.<init>(Compiled Code)
at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(Compiled Code)
at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:200)
at weblogic.servlet.jsp.JspStub.compilePage(Compiled Code)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:173)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:187)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:118)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:142)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:744)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:692)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:363)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:263)
at weblogic.kernel.ExecuteThread.run(Compiled Code)
The default Java compiler from sun lives in the tools.jar that comes with
the JDK. Just add that to your set of JARs which are deployed in production
and you should be fine. No need to install the full JDK - just make the
tools.jar available to WebLogic.
Regards
James
James Strachan
=============
email: [email protected]
web: http://www.metastuff.com
"Martin Webb" <[email protected]> wrote in message
news:[email protected]...
>
> How can WLS use JSP pages in a Web Application (either a .war file or a
war directory structure) without a java compiler?
>
> I suspect either the JSP specification is flawed (i.e. it doesn't take
account of servers using just a JRE), or BEA's implementation is broken.
>
> Production servers do not have a JDK installed. They only have a JRE.
Therfore a java compiler is not present on the machine that the Web
Application is deployed onto.
>
> On the development machine, when the server is requested to load the JSP
it creates a tmpwar directory within the Web Application directory
structure. This is then included in the resultant .war file thus:
>
> D:\war>jar -tf gmi.war
> META-INF/
> META-INF/MANIFEST.MF
> gmiService.jsp
> WEB-INF/
> WEB-INF/classes/
> WEB-INF/classes/com/
> WEB-INF/classes/com/bt/
> WEB-INF/classes/com/bt/gmi/
> WEB-INF/classes/com/bt/gmi/gmiService.class
> WEB-INF/getList.xsl
> WEB-INF/getListByConnection.xsl
> WEB-INF/getListByDistrict.xsl
> WEB-INF/getListByDistrictConnection.xsl
> WEB-INF/lib/
> WEB-INF/source/
> WEB-INF/source/build.bat
> WEB-INF/source/gmiService.java
> WEB-INF/web.xml
> WEB-INF/weblogic.xml
> tmpwar/
> tmpwar/jsp_servlet/
> tmpwar/jsp_servlet/_gmiservice.class
> tmpwar/jsp_servlet/_gmiservice.java
>
> When deployed on the production server with the web.xml file set to use
the following values (note XML stripped):
>
> weblogic.jsp.pageCheckSeconds
> -1
>
> weblogic.jsp.precompile
> false
>
> weblogic.jsp.compileCommand
> javac
>
> weblogic.jsp.verbose
> true
>
> weblogic.jsp.packagePrefix
> jsp_servlet
>
> weblogic.jsp.keepgenerated
> false
>
>
> And in the weblogic.properties file:
>
> weblogic.httpd.webApp.gmi=war/gmi
>
> I've also tried with the .war file, but that insists on creating another
tmpwar directory outside of the .war file.
>
>
> Then, although I have set pageCheckSeconds to -1 (don't check and don't
recompile) ter production server still attempts to recompile the JSP's:
>
>
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: init
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
verbose initialized to: true
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
packagePrefix initialized to: jsp_servlet
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
compileCommand initialized to: javac
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
srcCompiler initialized to weblogic.jspc
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
superclass initialized to null
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
workingDir initialized to:
/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp: param
pageCheckSeconds initialized to: -1
> Mon Sep 25 11:40:11 BST 2000:<I> <WebAppServletContext-gmi> *.jsp:
initialization complete
> Mon Sep 25 11:40:12 BST 2000:<I> <WebAppServletContext-gmi> Generated java
file:
/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.
java
> Mon Sep 25 11:40:14 BST 2000:<E> <WebAppServletContext-gmi> Compilation of
/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.
java failed: Exception in thread "main" java.lang.NoClassDefFoundError:
sun/tools/javac/Main
>
> java.io.IOException: Compiler failed
executable.exec([Ljava.lang.String;[javac, -classpath,
/opt/Solaris_JRE_1.2.1_04/lib/rt.jar:/opt/Solaris_JRE_1.2.1_04/lib/i18n.jar:
/opt/Solaris_JRE_1.2.1_04/classes:/var/wls/5.1/weblogic/lib/weblogic510sp4bo
ot.jar:/var/wls/5.1/weblogic/classes/boot:/var/wls/5.1/weblogic/eval/cloudsc
ape/lib/cloudscape.jar:/var/wls/5.1/weblogic/lib/wleorb.jar:/var/wls/5.1/web
logic/lib/wlepool.jar:/var/wls/5.1/weblogic/lib/weblogic510sp4.jar:/var/wls/
5.1/weblogic/license:/var/wls/5.1/weblogic/classes:/var/wls/5.1/weblogic/lib
/weblogicaux.jar:/opt/wls-servers/gmiServer/weblogic/gmiServer/serverclasses
:/opt/wls-servers/gmiServer/weblogic/lotusxsl.jar:/opt/wls-servers/gmiServer
/weblogic/xerces.jar:/opt/wls-servers/gmiServer/weblogic/logging.jar::/opt/w
ls-servers/gmiServer/weblogic/war/gmi/WEB-INF/classes:/opt/wls-servers/gmiSe
rver/weblogic/war/gmi/_tmp_war, -d,
/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war,
/opt/wls-servers/gmiServer/weblogic/war/gmi/_tmp_war/jsp_servlet/gmiService.
java])
> at java.lang.Throwable.fillInStackTrace(Native Method)
> at java.lang.Throwable.fillInStackTrace(Compiled Code)
> at java.lang.Throwable.<init>(Compiled Code)
> at java.lang.Exception.<init>(Compiled Code)
> at java.io.IOException.<init>(Compiled Code)
> at
weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(Compiled Code)
> at
weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:200)
> at weblogic.servlet.jsp.JspStub.compilePage(Compiled Code)
> at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:173)
> at
weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:18
7)
> at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:118)
> at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:142)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:744)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:692)
> at
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
Manager.java:251)
> at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:363)
> at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:263)
> at weblogic.kernel.ExecuteThread.run(Compiled Code)
>
>
>
-
Slow Oracle Forms 10gR2 using Sun's JRE on Windows 7 x64 laptops and its wo
Slow Oracle Forms 10gR2 using Sun's JRE on Windows 7 x64 laptops and its working good in same windows 7 x64 destops.
Hi,
Try posting your question on the Forms forum: Forms
Andy -
How to open MSWORD using JAVA/JNI and write the database entries into WORD
Hi..
I am searching for java codes that uses JAVA NATIVE INTERFACE (JNI) for opening MSWORD 2003.
To be brief.
I created HTML form called Employee_data.
if i click on Submit button a word document should be opened.This should be using JNI.
I have also created a servlet in jsp to process the form data and store it into database(mysql).;
Please help me to find the codes to open MSWORD on submit click and to write the database entries into word file.Can i get the full code for that.This is so urgent.
Thanks in advance.Hi Suresh,
The easest solution I can think of is to copy the math equation from the PowerPoint then paste in the Word document directly, there's actually no way to convert it to plain text, some equation is very complext, String variable is not suitable in this case.
For example, this code works fine:
var powerPoint = new Application { WindowState = PpWindowState.ppWindowMinimized };
var oPresSet = powerPoint.Presentations;
Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"C:\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
var strObj = oPres.Slides[1].NotesPage.Shapes[2].TextFrame2.TextRange.MathZones.get_MathZones();
strObj.Copy();
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add();
doc.Range(0, 0).Paste();
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Maybe you are looking for
-
I've attempted disabling all firewalls (both PC and anti-virus), disabling ipv6, rebooting the airport unit itself, but no luck. I'm not prompted with an error, however, as itunes is attempting to connect the airplay icon turns blue, and when it does
-
i shifted from a windows to a mac.. I want to add songs to my ipod tpuch 4th gen.. but if i try to sync with itunes it says my songs will be replaced by the new songs.. Is there any way that i can have my previous data safe??
-
ever since i downloaded the 4.0 version of firefox, it has not worked on either computer[ macs] - earlier versions worked fine. It refuses to load pages and freezes [ on various sites , not just one]so i have to force quit it over and over.
-
Dynamically create TRAY view element.
I am trying to create a little menu using a stack of trays with related buttons under each tray. I cannot find an example of a dynamically created tray. Every instance of NEW_TRAY in my NW07 system is generated and the system won't show it to me so
-
Why the item is transfered to expense location after being receipt, as the routing is set to "Inspection Required"?