Using a library (jcurses) that uses jni

I'm having trouble uses the JCurses library. Here's what's happening:
ls -Ajcurses.jar  .keepme  libjcurses.so  Test.java
javac Test.java -classpath jcurses.jar
ls -Ajcurses.jar  .keepme  libjcurses.so  Test.class  Test.java
java Test -classpath jcurses.jarException in thread "main" java.lang.NoClassDefFoundError: jcurses/system/Toolkit
        at Test.main(Test.java:6)
rm Test.class
jar xvf jcurses.jar jcurses/...(no jar error outputs)...
ls -Ajcurses/ jcurses.jar  .keepme  libjcurses.so  Test.java
javac Test.java
ls -Ajcurses/ jcurses.jar  .keepme  libjcurses.so  Test.class  Test.java
java TestException in thread "main" java.lang.ExceptionInInitializerError
        at Test.main(Test.java:6)
Caused by: java.lang.NullPointerException
        at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)
        at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
        ... 1 moreWhy does running "java Test" the first time output something different than the second just because? Also, why isn't the second working?

Ok I got it working now. I used
>java -cp .:jcurses.jar TestThe part that was really confusing me was:
>java -cp jcurses.jar Test
Exception in thread "main" java.lang.NoClassDefFoundError: TestI forgot that the java command only includes the current directory in the classpath if none is specified. Thats why >java Test worked: it used the default classpath which consists of the current directory, and the class I was executing and the library I was using were both in the current directory, so java located them, but the library failed because its classes assume that they will be executed from a jar. The reason >java -cp jcurses.jar Test didn't work is because the current directory was no longer part of the classpath, so java couldn't find the Test class which was in the current directory.
Thanks.

Similar Messages

  • HT1347 When I add a folder to the library, does that mean that 'later' when I drop a new file into that folder (already added) it will automatically end up in iTunes? (or do I have to add file/folder to library every time I have a new file??) I'm using XP

    When I add a folder to the library, does that mean that 'later' when I drop a new file into that folder (already added) it will automatically end up in iTunes? (or do I have to add file/folder to library every time I have a new file??) I'm using XP...

    iTunes does not actively scan the media folders.  If you manually add content to a folder, then you must add that content to iTunes manually via the File > Add File/Folder feature.
    The only folder that gets scanned is the "Automatically add to iTunes" folder.

  • 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);
    &#12288;
    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();
    &#12288;
    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 AM

    0x49202400 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

  • 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!!!
    Sonu

    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!!!
    Sonu

  • Trouble using JNI

    Hi everyone
    I have a problem, with a class which has native functions(JNI).
    The application I�m developing, uses thread�s. At the beginning before thread starts his job, application calls a native function without problem. But when another thread calls another native function(same class) generates the next error :
    java.lang.UnsatisfiedLinkError: estarEnEjecucion
    at MemoriaCompartida.estarEnEjecucion(Native Method)
    at MemoriaCompartida.estarEnEjecucion(MemoriaCompartida.java:72)
    at Censor.timerIntervalo(Censor.java:82)
    at Timer.run(Timer.java:225)
    at java.lang.Thread.run(Thread.java:534)
    What seems to be the problem???
    Thanks a lot for your help

    First of all,
    when I use JNI, I like to put the System.loadLibrary() on a static method in the first class I know will be loaded.
    like this:
    static {
        System.loadLibrary("Name");
    }So I know that Library was succesfuly loaded.
    Anyway, I bet that your library do NOT have the method you are trying to access, or maybe is missing parameters!
    Check it!
    If I didn't helped, please put the call of the methods in the java file and the library, if you can.
    Cya...
    Message was edited by:
    pbulgarelli
    Message was edited by:
    pbulgarelli

  • How to use JNI in an Applet?

    Can a native method can be invoken in an Applet?If it can,which knowledge of Java should be used and how to use it?

    You could I suppose if yo sign the applet (which, if the user accepts it, will allow it to use features otherwise not available to an applet because of the secure sandbox). However, I am not sure how you would deploy the necessary native library since it must be available to the native OS loader (ie, a file on the client machine). If you are deploying the applets (see WebStart perhaps) you could do it.
    But generally it is a poor idea to try to use JNI in an Applet, and this is probably something that you would not want to use outside of an intranet environment.
    Chuck

  • Unable to create JVM using JNI

    Hai,
    I am new to java programming. I am trying to invoke native application using JVM. I have a written a pilot code in C using JNI. I am getting the following error when I try to run the binary. I think that the problem is from the fact that 1.2.2 is installed in
    /usr/bin directory (and is the default on the server). But I have set both
    LD_LIBRARY_PATH, PATH and path
    so that it points out 1.4.2. Here is the error
    unable to create JVM
    There was an error trying to initialize the HPI library.
    Please check your installation, HotSpot does not work correctly
    when installed in the JDK 1.2 Solaris Production Release, or
    with any JDK 1.1.x release.
    while building the binary I am using JDK1.4.1 header and lib files
    These are my compilation arguments
    g++ -g -I/opt/BES/jdk/jdk1.4.1/include/ -I/opt/BES/jdk/jdk1.4.1/include/solaris/ -L/opt/BES/jdk/jdk1.4.1/jre/lib/sparc/ -ljvm -ljava jniTest.C
    Help Needed
    Thanks
    Sunil

    I haven't seen this before. Could it be a disk space issue?
    Are you using JDevStudio or JDevStudioBase? And do you have your JAVA_HOME set? If you are using JDevStudio, try running JDev in a command window where JAVA_HOME is not set - I'm pretty sure JDev does NOT get confused about this but I haven't done extensive testing.
    Also you should try deleting and unzipping JDev again.
    Finally, search the JDev TP forum - there are some discussions there about this error and you may find an answer to your specific configuration - it doesn't seem to be a TP4 specific issue.
    JDeveloper and OC4J 11g Technology Preview
    Heidi.

  • How can I use JNI in JDeveloper???

    hi
    I have a native mathod,it can work very well use JCreator or JDK's Java command.
    But it can't work in Jdeveloper with the errors :
    java.lang.UnsatisfiedLinkError: no JniConvert in java.library.path
    void java.lang.ClassLoader.loadLibrary(java.lang.Class, java.lang.String, boolean)
    void java.lang.Runtime.loadLibrary0(java.lang.Class, java.lang.String)
    void java.lang.System.loadLibrary(java.lang.String)
    void myInterMediaPackage.ArithmaticBean.<clinit>()
    void DrawTest.init()
    void DrawTest.main(java.lang.String[])
    Who have used JNI in JDeveloper or can help me?
    I appreciate anyone's help;

    Dennis ,
    Thank you very much.
    I have resolved that question according to your second option.
    thank you again!
    Good luck.
    2 options, that I know of (windoze, right?):
    1. Add "-Djava.library.path=c:\<blah>\" (the location of your native DLL) to the "Java Options:" field in the "Project Settings/Configurations/Development/Runner" window. OR
    2. Put your DLL in a folder that is on your PATH (e.g., c:\winnt\system32).
    If you deploy it to a jar, and put the DLL in there, I'd think it would see it - but I haven't gotten THERE, yet! :-P
    Later.
    Dennis

  • I have problem when use 'JNI'

    Hello every body,
    I have an application language "C", which, I must make a wrapper java.
    To do this using "JNI".
    First I try to understand the functioning of JNI, I try it for the first example helloWorld.
    all steps works well, and dynamic library was well create: libHelloWorld.so
    The execution, it does'nt work
    When I try to java Helloworld, here's what I see:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/java/jniexamples/HelloWorld/libHelloWorld.so: Can't load IA 32-bit .so on a IA 32-bit platform
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
    at java.lang.Runtime.loadLibrary0(Runtime.java:822)
    at java.lang.System.loadLibrary(System.java:993)
    at HelloWorld.<clinit>(HelloWorld.java:7)
    Although I added the link to my library like this:
    export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: / home / Install / java / jniexamples / HelloWorld
    I dont understand where is the problem may be in the version I use of java, I use jdk-1.5.0-13?
    Thank you in advance for your help
    Regards
    Daniel

    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/java/jniexamples/HelloWorld/libHelloWorld.so: Can't load IA 32-bit .so As a guess that would suggest that it found a file (thus the name is correct) but that the contents do not represent a shared library that the VM will load.
    That is usually because the compile/link options are wrong for the target VM.

  • Using JNI in JSP

    Hi
    i am going to develop a DI COM viewer in web.
    so that it uses lot of shared libraries (.dll).
    i tried JNI with servlet it works fine.
    but when i try to load a same DLL for another page it gives an error saying
    ".dll loaded in another class loader"
    So that i tried to write JNI wrapper as a component using java beans.
    and i can use as multiple instances.
    package BeanDir;
    import java.util.*;
    //This file must be compiled Manually using javac
    //cd D:\tomcat\webapps\examples\WEB-INF\classes\BeanDir\mysimplebean.java
    public class mysimplebean
         static
              System.loadLibrary("HelloWorld");
         public String getceoname()
              String ceonameval = "Tom Hanks CEO of Tom Hanks INC";          
              return ceonameval;
         public String ceoemail()
              String ceoemailval = "[email protected]";          
              return ceoemailval;
         public double findtakehome(int salary,String designation)
              double takehomeamt;
              if(designation=="Developer")
                   takehomeamt = salary+salary*0.15; //15 % Raise in Salary
              else
                   takehomeamt = salary+salary*0.10; //10 % Raise in Salary
              return takehomeamt;
         public native String sayHello();      
    }Then i added the Java bean in JSP:
    <%@ page import = "BeanDir.mysimplebean" %>
    <jsp:useBean
         id="mybeanid"
         class="BeanDir.mysimplebean"
         scope="session"/>
    <jsp:setProperty
         name="mybeanid"
         property="*"/>
    <html>
    <head><title>JSP - Java Bean Demo </title></head>
    <body bgcolor="white">
    <font size=2 face=verdana>
    <center><strong>Simple JSP with JAVA Beans Demo Application Form</strong> <br>
    <%
    //Auto Compiled by JSP Engine dont use Javac
    //No Parameters Passed into Bean
    //cd E:/tomcat/webapps/examples/jsp/testdir/testme2.jsp
    String ceoname_ret;
    ceoname_ret=mybeanid.getceoname();          
    out.println("<br>CEO Name : "+ceoname_ret);
    //No Parameters Passed into Bean
    String ceoemail_ret;
    String s;
    ceoemail_ret=mybeanid.ceoemail();
    out.println("<br>CEO Email : "+ceoemail_ret);
    out.println("<br><br>");
    out.println("<table border=1 bordercolor='maroon' cellspacing=4 cellpadding=4 align=center>");
    out.println("<tr align=center valign=middle>");
    out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> Calling From JSP </font></td>");
    out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> BEAN BEANING CALLED </font></td></tr>");
    double takehomeamt_ret;     
    double totalcost=0;
    takehomeamt_ret = mybeanid.findtakehome(5000,"Developer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : James Smith  </font></td>");
    out.println("<td><font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    takehomeamt_ret = mybeanid.findtakehome(5000,"Designer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home :  Andrew  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    takehomeamt_ret = mybeanid.findtakehome(7000,"Developer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : Peter O Neal  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2><strong>TOTAL COST FOR COMPANY </strong>  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+totalcost+"</font></td></tr>");
    out.println("</table>");
    out.print("My dll should be somewhere here: "+System.getProperty("java.library.path"));
    s = mybeanid.sayHello();
    out.println("<br>Output from JNI"+s);
    %>  </center>
    </font>
    </body>
    </html>Error which i am getting is :
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:121)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         BeanDir.mysimplebean.sayHello(Native Method)
         org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:109)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
    Apache Tomcat/6.0.20

    Hi friends,
    i got the solution for using JNI in JSP.
    But not with Javabean
    I created a class that loads the library and define the native method.
    import the above said class package in your JSP program
    create the object for the class
    access the native method with that object.
    copy your .dll file in system32 folder
    if you have declared package in java program change the method according to that
    other wise you will get unsatisfied link error
    for ex
    package sam.jni;
    import java.io.*;
    public class Helloworld
    static
    static.loadlibrary("HelloWorld");
    public native String sayHello();
    }Method name in your c++ program looks like
    JNIEXPORT jstring JNICALL Java_sam_jni_HelloWorld_sayHello
      (JNIEnv *env, jobject obj) {
        return  env->NewStringUTF("krishnakumar");

  • Advice needed... should I write it using JNI?

    Hi all - I'm experienced with both Java & c++. I've got a set of libraries written in c++, and I need to write a test harness. It's been suggested that I write it using JNI. I've no experience with JNI, only gone through the tutorials.
    The library & test harness will be used on a multitude of platforms (Windows, Sun, Linux, Netware, AIX, oh many more...).
    Based on my very limited understanding of JNI, I'd basically have to write a harness in c++ (I can't touch the libraries themselves) using JNI-friendly methods and then access it with a pure Java app. Various reasons as to why this might be a good idea have been suggested, but I'd like some more experienced input.
    Is this a worthy use of JNI? I'm quite happy to learn it & do it, but is this the type of situation where I'd want to? And am I totally off on what I'd have to do?
    Thanks in advance,
    Suzanne

    Hi,
    I had been working on JNI as well. It was a nice experience trying to communicate from java through c and finally to fortran libraries built long ago. Since rewriting the code was tedious Job we came out with this idea of JNI. During my reserach on JNI I came across with javah -stubs option. To my understanding if you could generate the stubs based header files. You can talk to c programs with minimum changes in interface. If this is just a test program then you can also communicate through sockets and built a interface between these two high level languages, where all the returned output will be redirected to ports where in finally you extract it from Java side and vice versa. I haven't tried the second idea but would be interesting to try though. Do let me know what u finally decide to do on forum.
    Thanks,
    Regards,
    RaviKiran.

  • Guidelines for when to use JNI

    I didn't find an answer to this in any FAQ or the 2 JNI books I have, so apologies in advance if this is a common question whose answer has already been posted -
    Do any guidelines exist for when, and to what extent, JNI should be used?
    I'm currently working on my second project where the question of whether or not to use it has come up. Both projects were distributed and contained both C++ and Java code in different areas. The issue came up when the need arose to implement a new shared library that had to be used by both C++ and Java code. Logging and configuration services are examples of the new functionality.
    The choice is whether to implement the new libraries primarily in C++ and supply a Java interface, via JNI, for Java code which needs to use it, or to implement the new libraries in both C++ and Java to support both types of clients.
    On the previous project, a team member had extensive JNI experience and recommended the dual language implementation approach instead of JNI. This worked out ok except we did have to have to ensure the new library developer was skilled in both C++ and Java, and he had to be sure to update both when changes to 1 were necessary - a maintenance problem. The experienced JNI developer made this recommendation due to issues he had encountered previously - most notably issues related to errors in the native code which brought down the JVM.
    On the current project, we're opting for base C++ implementations with JNI wrappers. That's making me somewhat nervous since the alternative seems safer.
    What do other developers think?

    Have you checked out www.javaworld.com. They usually have very good and in-depth articles. IMHO, it all depends on the sort of use your library is intended for. If its used extensively by native code, use C++ with a Java wrapper. It its the other way around, implement it in Java and use a JNI interface for native code. I would really consider this carefully before implementing stuff in C++ that is used from Java. First of all, Java is after all much simpler than C++, its a more elgant OO-language and you have the platform neutrality. On the other hand, C++ has its sides. I dont use JNI unless its absolutely neccessary, in situations like using legacy code.
    These are just a few of my thoughts, hope it gives you some hints.

  • We are using jni.h but its getting errors, please check it this

    We are using jni.h but its getting errors, please check it this
    Calling from a .dll using Java and JNI - by Borland Developer Support Staff
    Abstract:Basic JNI example: making a Win32 API call
    Making Native Windows API calls from within a Java Application
    One of the main points of Java is to be completely platform independent. However, sometimes it will occur that the developer of an
    application will know that his or her application is only going to be run on a specific platform, for example, Win32.
    NOTE: This example assumes that you are using JDK 1.2 or later.
    Below are the steps for writing a Java application that makes a Win32 API call. The application generates a Swing Jframe and makes it
    system modal, or gives it the �Always On Top� functionality, similar to that of the Windows NT Task Manager.
    Steps to follow:
    1. Write the Java code for the application
    2. Run javah.exe on your .class file to generate a C header file
    3. write the implementation of your native methods
    4. create the shared library
    5. run the application
    1. Write the Java code for the application
    import java.awt.*;
    import sun.awt.*;
    import sun.awt.windows.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Frame1 extends JFrame {
    int windowHWND = 0;
    JButton jButton1 = new JButton();
    public Frame1() {
    //windowHWND = this.getHwnd();
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public int getHwnd() {
    DrawingSurfaceInfo w = (DrawingSurfaceInfo) ((DrawingSurface) getPeer()).getDrawingSurfaceInfo();
    w.lock();
    WDrawingSurfaceInfo win32 = (WDrawingSurfaceInfo) w;
    int hwnd = win32.getHWnd();
    w.unlock();
    return hwnd;
    static {
    System.loadLibrary("windowOnTop");
    public static native void WindowAlwaysOnTop(int hwnd, boolean flag);
    public static void main(String[] args) {
    Frame1 frame11 = new Frame1();
    frame11.setSize(400,400);
    frame11.setVisible(true);
    private void jbInit() throws Exception {
    jButton1.setText("jButton1");
    this.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowOpened(WindowEvent e) {
    this_windowOpened(e);
    public void windowClosing(WindowEvent e) {
    this_windowClosing(e);
    this.getContentPane().add(jButton1, BorderLayout.NORTH);
    void this_windowOpened(WindowEvent e) {
    windowHWND = this.getHwnd();
    System.out.println("the value is: " + this.getHwnd());
    this.WindowAlwaysOnTop(windowHWND, true);
    void this_windowClosing(WindowEvent e) {
    System.exit(0);
    Once the code is written, compile it with Jbuilder or the command line javac.exe tool which will result in a generated .class file. You will use
    this .class file in the next step.
    2. Run javah.exe on your .class file to generate a C header file
    The following line represents the basic syntax for running javah.exe:
    javah Frame1
    where Frame1 is the name of the argument class.
    When you run javah.exe, it will generate a header file by the same name as your implementation but with a .h file extension. For this
    example the .h file that was generated from the above Java code will be emitted being that it is quite large.
    NOTE: Make sure that when you run javah.exe, it is the javah.exe that came with the same JDK that you will be compiling with as there may
    be some issues with using a version of javah.exe that is different from that of the JDK you are using to compile.
    3. write the implementation of your native methods
    Now that you have your Java source and your C header file, it is time to write the implementation of your native methods.
    Following is the C code that corresponds to the native methods declared in the Java code listed in step 1:
    #include "jni.h"
    #include "Frame1.h"
    #include <stdio.h>
    #include<windows.h>
    JNIEXPORT void JNICALL Java_Frame1_WindowAlwaysOnTop(JNIEnv *env, jclass obj, jint hwnd, jboolean flag)
    if (flag)
    SetWindowPos((HWND) hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
    else
    SetWindowPos((HWND) hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
    return;
    You will notice several things: one is that the function signature has �Java_Frame1_� preceeding the name of the function. If there was a
    package statement in the Java source, it would appear after ��Frame1_� in the function signature.
    Second, you will notice the #include �jni.h�. Normally this would be #include<jni.h>, depending on how you have your libraries set up within
    your C compiler.
    4. create the shared library
    Now you are ready to create the shared library. Using your C compiler, create a .dll file with the code from the C implementation file. Refer
    to the doccumentation of the C compiler for details on creating a .dll file.
    For those interested in using Borland C++ Builder:
    If you have got it installed, you could use Borland C++ Builder 3 or C++ Builder 4 to create your DLL file. If this is the case, you would use
    File | New... | DLL C++ Builder will then generate some code for you, and you will just need to add your implementation code to the code
    which was generated.
    Remember in the Java code in step one there is a line:
    static {
    System.loadLibrary("windowOnTop");
    �windowOnTop� is the name of the .dll file. You can name it whatever you want, just make sure that you specify the appropriate name when
    loading the library.
    5. run the application
    Finally you are ready to run the application. From the command line use java.exe and as the argument specify the name of the class that
    you compiled in step one. Once the system loads your DLL, the window that the VM creates should mimic the �Always On Top�
    functionality.
    We are getting errors like this
    �Compiling JNI.H:
    Error JNI_MD.H 23: , expected
    Error JNI.H 115: Declaration missing
    Error JNI.H 200: ) expected
    Error JNI.H 202: ) expected

    #include "jni.h"
    #include "Frame1.h"
    #include <stdio.h>
    #include<windows.h>
    JNIEXPORT void JNICALL Java_Frame1_WindowAlwaysOnTop(JNIEnv *env, jclass obj, jint hwnd, jboolean flag)
    if (flag)
    SetWindowPos((HWND) hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
    else
    SetWindowPos((HWND) hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
    return;
    We are getting errors like this
    �Compiling JNI.H:
    Error JNI_MD.H 23: , expected
    Error JNI.H 115: Declaration missing
    Error JNI.H 200: ) expected
    Error JNI.H 202: ) expected

  • Executing DLLs from Java using JNI vs Runtime.exec()

    I am trying to understand the best way to execute a dll using java. The dll I am testing with takes a few input parameter. If I use JNI with System.loadLibrary("dll"); what do I need to do to pass the arguements in as well? Can I just add the arguements in the java code like private int xyz = "value"; and expect that the dll will accept them or is there special definitions I have to set up in the dll to make it work?
    Alternatively I was looking at using Runtime to execute the dll by using Runtime.exec("dll param1 param2",env,filePath); Does anyone know if there are drawback to doing it this way vs. using JNI or is this just as efficient? Any help would be appreciated.

    You seem to be confused...
    "execute a dll using java"
    Unless I'm mistaken, a dll is not executable. A dll is a library of code. This code has (hopefully) some well-defined entry points (declared in a header file somewhere) which you must call in a C/C++ file. The arguments you pass to the dll will come from java through JNI.
    As far as your understanding of this entire process, it is obviously confused beyond the scope of a simple reply. I recommend you read the examples and ALL of the documentation available here:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    When you get the/an example running (or just set up to run) then post your code and comments here for more help.
    Ian

  • How can i call a VB6 project from my java application using JNI

    hi
    can anyone tell me the procedure of calling a VB6 project from any java application using JNI
    if anyone does know then tell me the detail procedure of doing that. I know that i have to create a dll of that VB6 project then to call it from the java application.
    if anyone know that procedure of creating dll file of an existing VB6 project please reply
    please if anyone know then let me know

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • CMD+ any shortcut doesn't work in Safari after upgrading to Yosemite

    After upgrading from Mavericks to OS X Yosemite 10.10 not a single CMD+ shortcut works?! For example CMD+tab works (switching between apps), ctrl+tab works (switching between tabs), but none of these work: CMD+W, CMD+Q, CMD+F, CMD+C, CMD+X, CMD+P...

  • Java.lang.NoSuchMethodError: main

    I am still trying to read a csv file, but getting an error, see subject. I think I nust go on a course as I just can't believe that it's thar hard just to read a simple csv file in java. Can anybody recommend a good course that will explain all. This

  • Vibrate Mode only works for phone calls -- Solution.

    So, I'm sure I'm not the only person who didn't realize that the vibrate mode doesn't turn on vibration for message and app notifications. I was having an issue where whenever I had the phone on vibrate, I was not getting notified for text messages.

  • Where is Flash builder 4.6 for php ?

    Hello, I found flash builder 4.5 for php and flash builder 4.6, where is flash builder 4.6 for php ?

  • How to turning the large dimension query in the Analyzer 6.2?

    Dear expert:I need to query a report in the Analyzer 6.2How to turning the performance in the large sparse dimension query in the Analyzer 6.2 and essbase 6.5.1? ---------------------------------------Report is look like: page : order_date sub_code i