G++ / JNI / dependencies

Hi,
I'm trying to build a jni library on SPARC Solaris 8 using g++. The library works just fine, however I appear to have to have libgcc installed on the machines where I want to use the library.
I'm building the library with the following command line:
g++ -I/usr/java/include -I/usr/java/include/solaris -G -o libasres.so asres.cpp
If I move the libasres.so file to a virgin machine I get the following exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /export/home/searl/asres/libasres.so: ld.so.1: java: fatal: libstdc++.so.5: open failed: No such file or directory
How can I build this library to enable me to distribute a single file rather than requiring the user to install other libraries?
Thanks in advance,
Steve...

Hi Steve.
I believe that what you want to look at is statically linked libraries. My understanding is that the library code is then included in your library.
Please verify this and the syntax with your compiler/linker.
-Steve

Similar Messages

  • Whether postgresql-8.2-506.jdbc4 works in a 64 bit operating system?

    Whether **postgresql-8.2-506.jdbc4** works in a 64 bit operating system?
    Especially I would like to know whether it works in windows server 2008 64 bit operating system.

    masijade. wrote:
    :sigh:
    IOW, Go to a PostGreSQL site and ask there!
    The Driver is produced by them, they should know. I don't believe it would be a problem, but all you can do is try it.Agreed.
    The postgresql JDBC driver is a type 4 driver and therefor a pure Java implementation without JNI dependencies. That should work without problems on a 64 bit system.

  • Java Webservice calling C function through JNI

    I have a java class that is using the JNI to call native interface written in C. The called C function has dependencies in vendor supplied c function library in .lib (CAUEVT.LIB) format. I compiled the C function as .DLL file and put the .DLL file in the -Djava.library.path and same thing I put in the opmn.xml file for the Java option.
    Now, when I run the Java class from command line it works fine and makes call to the external system everything works fine.
    However, when I deploy the same as web service and try to test the web service, Java expects the external library also in .DLL format (The error message is "This application has failed to start because CAUEVT.dll was not found. Re-installing the application may fix this problem")
    If I look the application log file, I see the following error.
    java.lang.UnsatisfiedLinkError: D:\lib\CAEventLoggerImp.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
    I am wondering if the java class can run without any problem, why is the webservice execution fails....?

    The problem was that when Java loads the shared DLL we create from the java.library.path setting, but if the loaded DLL refers to any other DLL, it expects it from the System path. And for some reason, OC4J, doesn't expose all the system path unless entered in the Evnironment Variable explicitly in the Administration tab in OEM., server properties in the OEM. (opmn.xml)
    IT works fine after these changes.

  • How to use VS2005 dlls with jni?

    Hello,
    I have a java application using jni and some dlls.
    Previously this dlls were created using VS2003. Now I want to use VS2005 and I
    encountered some problems.
    Everything is working on my station were I have installed VS2005 but when I try to run the
    application on other station (a test station) is not working.
    I get the following error:
    java.lang.UnsatisfiedLinkError: C:\App\Test.dll: This application has failed to start because
    the application configuration is incorrect. Reinstalling the application may fix this problem
         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
         at java.lang.ClassLoader.loadLibrary0(Unknown Source)
         ......First I tried to search all the dependences and copied all missing dlls from my work station to the test
    station in the application directory. Still not working.
    when dlls were made with VS2003 I had only 3 dependences: mfc71d, msvcp71d, msvcr71d. With this dlls in
    the application directory everything was fine.
    Second I tried to install .Net framework(2.0) and vcredist (VS2005_sp1) but still nothing.
    What I'm doing wrong? Is somebody which is using dlls made in VS2005 with jni?
    Thank you
    ,Dragos

    IIRC, that message means the manifest file in the DLL points to assembly that your computer doesn't have, or it has no manifest file.
    You either need to:
    -recompile using static linking so that it has no dependencies
    -stick the correct manifest in
    -include the entire SxS (site by side) assembly folders with your application (only the ones you're dependent on). These are found in something similar to:
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86

  • JNI with Visual C++

    Hi,
    I am a newbie. I have a code using Visual C++ with integrated libraries. Can I interface it with Java ?
    Regards,
    D. Anand Kumar

    Hi,
    I can explain more on the question. I would like to write a program in Java which calls a native method that's described in a C++ program.
    Sample.java
    public class Sample
         static
              System.loadLibrary("Sample");
         // A native method that receives nothing and returns void
         private native void test();
         public static void main(String[] args)
              new Sample().test(); // invoke the native method
    Sample.cpp
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    void test() // native function
    // function definition
    I compiled and builded the Sample.cpp in a Visual C++ environment into a .dll. Now I tried to execute the java program with this dll and it said it could not find dependent libraries. I tried the following too.
    #include <jni.h>
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    JNIEXPORT void JNICALL Java_RUI_test(JNIEnv *env, jobject thisObj)
    //code
    I added additional dependencies to the program to include the jni header from JAVA_HOME/include and JAVA_HOME/include/Win32. I builded a dll and tried to execute the java code and hit again at the same error "Unsatisfied Link Error : Cant find dependent libraries".

  • JNI : DLL cannot be

    Hello,
    I am using a DLL through JNI.
    Up to now, my program works perfectly on all computers and systems.
    But, I encountered an error on one computer as if it couldn't find the dll (whereas it is well located):
    java.lang.UnsatisfiedLinkError: D:\Projects\Java\Tool\Native.dll: Can't find dependent libraries
         at java.lang.ClassLoader$NativeLibrary.load(Native Method)Can someone help me, please ?
    Note:
    If I removed that dll on a system that works normally, I encountered that error:
    java.lang.UnsatisfiedLinkError: no Native in java.library.path
         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1491)

    Greetings, Catharsis. I have a quite similar situation.
    I am working on a project which uses a comercial API (Netica, from Norsis) through a dll (dll A). dll A interacts, through JNI, with another dll (dll B). I checked this dependency with a program to inspect DLL features (dependencies, for example).
    What happens is that an error-window pops out saying that it cannot find dll B on which the one I load (dll A), depends on.
    I don't use static blocks with System.loadLibrary, since this is done by a runtime variable I use, upon its initialization.
    I assigned the user path variable's value for these dlls' directory to the system path's variable and still I get the error.
    I used a file access monitor to find out that dll A tries to load dll B on a directory one level above the original (and correct) one.
    What's strange:
    1- It only happens in one recently configured Windows PC. Path variables and instalation directories are equal between PC where it works and the other where it doesn't.
    2- I also tried to build JNI code for another project in the PC which prompts the error, and it yelds errors in jni.h from jdk 1.5. (so I have this feeling that something's wrong with this PCs JNI)
    Note:
    1- jdk was reinstalled;
    2- the comercial API, whose installation sums up to extraction to install dir and path variable tuning, was reinstalled; and,
    2- Eclipse's project settings are equal between the two PCs, since one project is a full copy of the other.
    Any ideas?
    Best regards.

  • Csdkjni.dll cannot find dependencies

    Well this is probably a long shot since no one has posted here in months... Wonder why Oracle? You only make it damn near impossible to find or get the SDK let alone provide reasonable documentation for preparing the development environment. Okay, I'm obviously frustrated.
    Here is the problem (trying to run CSDKDemo):
    Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\product\10.1.2\ocs_1\ocal\lib\csdkjni.dll: Can't find dependent libraries
         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
         at java.lang.ClassLoader.loadLibrary0(Unknown Source)
         at java.lang.ClassLoader.loadLibrary(Unknown Source)
         at java.lang.Runtime.loadLibrary0(Unknown Source)
         at java.lang.System.loadLibrary(Unknown Source)
         at oracle.calendar.sdk.Api.loadJniLib(Unknown Source)
         at oracle.calendar.sdk.Api.init(Unknown Source)
         at calendardemo.CalendarSession.init(CalendarSession.java:46)
         at calendardemo.CalendarSession.<init>(CalendarSession.java:26)
         at calendardemo.CSDKDemo.main(CSDKDemo.java:23)
    I've search and looked through every thread, every JNI troubleshooting page, used dependency walker on csdkjni.dll, etc.
    I'm trying to compile this in eclipse IDE, on Windows XP. Here is my VM command line argument:
    -Djava.library.path="C:\product\10.1.2\ocs_1\bin;C:\product\10.1.2\ocs_1\ocal\lib;C:\product\10.1.2\ocs_1\ocal\jlib"
    The jlib and bin directories are there because I saw the suggestion somewhere in my searching. Everything works the same with just the lib directory also. It's obviously finding the csdk.jar and it's finding csdkjni.dll also, but not one of its dependencies. According to dumpbin.exe it's dependencies are:
    capi.dll
    MSVCRT.dll
    KERNEL32.dll
    Everything is found when I run dependency walker. capi.dll is located in the same directory as csdkjni.dll. This directory has been added to my system's PATH environment variable. I've also tried putting capi.dll in every folder I could think of with no luck. I'm totally out of ideas and cannot believe I've lost an entire day just trying to get the demo to compile. Does ANYONE have a clue whats going on here?
    Is it possible that this error message is just not correct and that its actually having a problem loading some function from the DLL?

    You appear to have already tried all the usual suggestions. There is a thread Calendar SDK on Win XP where the problem seems to be due to file conflict with some other software also using capi.dll. Could that apply in your case?
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Cpptasks - working hello world jni example on linux

    I have a working hello world example working on linux that uses cpptasks for the build. I'll post it here as I don't see any info on this out there. I hope this is helpful for you.
    -Todd
    Contents:
    - build.xml
    - helloworld.c
    - helloWorldCWrapper.java
    - directory structure
    - environment vars
    - output : $ant build
    - output : $ant run
    - References
    build.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <project basedir="." default="build" name="myJni">
         <property name="build" value="build"/>
         <property name="src" value="src"/>
         <property name="stub" location="stub"/>
         <property environment="os"/>
    <!-- Load the cpptasks task -->
    <taskdef resource="cpptasks.tasks"/>
    <typedef resource="cpptasks.types"/>
         <path id="project.classpath">
    <pathelement location="${build}"/>
    <pathelement location="."/>
    </path>
         <target name="init">
              <mkdir dir="${build}"/>
              <mkdir dir="${stub}"/>
    </target>
    <target name="clean" depends="init">      
              <delete>
                   <fileset dir="${build}">
                   <include name="*.class"/>
                   </fileset>
                   <fileset dir="${stub}">
                   <include name="*.h"/>
                   <include name="*.c"/>
                   </fileset>
              </delete>
         </target>
    <target name="jni-compile" description="--> create the jni h/c files">
         <javah class="com.bigdog.jni.helloWorldCWrapper" destdir="${stub}" verbose="yes" force="yes">
              <classpath refid="project.classpath"/>
         </javah>      
    </target>
         <target name="build" depends="init, java-compile, jni-compile, c-compile">
    </target>
         <target name="java-compile">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac destdir="${build}">
    <src path="${src}"/>
    <classpath refid="project.classpath"/>
    </javac>
         </target>
    <target name="c-compile" description="--> compile c code">
    <cc link="shared" outtype="shared" multithreaded="true" optimize="speed"
    objdir="${build}" outfile="${build}/libhelloworld">
    <compilerarg value="-Wall"/>
    <compilerarg value="-D_JNI_IMPLEMENTATION_"/>
    <compilerarg value="-fno-strict-aliasing"/>
    <linker name="g++">
              <linkerarg value="-olibhelloworld.so"/>
         </linker>
    <fileset dir="${src}" includes="helloworld.c"/>
         <includepath>
              <path path="${os.JAVA_HOME}/include"/>
              <path path="${os.JAVA_HOME}/include/linux"/>
              <path path="${basedir}/stub"/>
              <path path="${build}"/>
         </includepath>
    </cc>
    </target>
         <target name="run">
    <echo message="${ant.project.name}: ${ant.file}"/>
              <echo message="java.library.path = ${java.library.path}"/>
              <echo message="LD_LIBRARY_PATH = ${os.LD_LIBRARY_PATH}"/>
    <java classname="com.bigdog.jni.helloWorldCWrapper">
    <classpath refid="project.classpath"/>
    </java>
         </target>
    </project>
    helloworld.c
    #include <jni.h>
    #include <stdio.h>
    #include "com_bigdog_jni_helloWorldCWrapper.h"
    JNIEXPORT void JNICALL
    Java_com_bigdog_jni_helloWorldCWrapper_print(JNIEnv *env, jobject obj)
              printf("Hello world :o)\n");
              return;
    helloWorldCWrapper.java
    package com.bigdog.jni;
    public class helloWorldCWrapper {
         private native void print();
         public static void main(String[] args) {
              new helloWorldCWrapper().print();               
         static {
              System.loadLibrary("helloworld");
    directory structure
    ./.project
    ./.classpath
    ./build
    ./build/com
    ./build/com/bigdog
    ./build/com/bigdog/jni
    ./build/com/bigdog/jni/helloWorldCWrapper.class
    ./build/history.xml
    ./build/helloworld.o
    ./build/libhelloworld.so
    ./build/dependencies.xml
    ./stub
    ./stub/com_bigdog_jni_helloWorldCWrapper.h
    ./src
    ./src/com
    ./src/com/bigdog
    ./src/com/bigdog/jni
    ./src/com/bigdog/jni/helloWorldCWrapper.java
    ./src/helloworld.c
    ./bin
    ./bin/helloworld.c
    ./build.xml
    ./build-user.xml
    ./history.xml
    environment vars
    user@machine:~/working/eclipse_proj/myJini$ export | grep LD
    declare -x LD_LIBRARY_PATH="/home/user/working/eclipse_proj/myJini/build"...
    Note: I had to modify the LD_LIBRARY_PATH in my .bashrc file. Modifying
    it from the command line seemed to have no effect.
    output : $ant build
    Buildfile: /home/user/working/eclipse_proj/myJini/build.xml
    init:
    java-compile:
    [echo] myJni: /home/user/working/eclipse_proj/myJini/build.xml
    [javac] Compiling 1 source file to /home/user/working/eclipse_proj/myJini/build
    jni-compile:
    [javah] [Search path = /home/user/bin/jdk1.5.0_03/jre/lib/rt.jar:/home/user/bin/jdk1.5.0_03/jre/lib/i18n.jar:/home/user/bin/jdk1.5.0_03/jre/lib/sunrsasign.jar:/home/user/bin/jdk1.5.0_03/jre/lib/jsse.jar:/home/user/bin/jdk1.5.0_03/jre/lib/jce.jar:/home/user/bin/jdk1.5.0_03/jre/lib/charsets.jar:/home/user/bin/jdk1.5.0_03/jre/classes:/home/user/working/eclipse_proj/myJini/build:/home/user/working/eclipse_proj/myJini]
    [javah] [Loaded /home/user/working/eclipse_proj/myJini/build/com/bigdog/jni/helloWorldCWrapper.class]
    [javah] [Loaded /home/user/bin/jdk1.5.0_03/jre/lib/rt.jar(java/lang/Object.class)]
    [javah] [Forcefully writing file /home/user/working/eclipse_proj/myJini/stub/com_bigdog_jni_helloWorldCWrapper.h]
    c-compile:
    [cc] Starting dependency analysis for 1 files.
    [cc] 0 files are up to date.
    [cc] 1 files to be recompiled from dependency analysis.
    [cc] 1 total files to be compiled.
    [cc] Starting link
    build:
    BUILD SUCCESSFUL
    Total time: 2 seconds
    output : $ant run
    Buildfile: /home/user/working/eclipse_proj/myJini/build.xml
    run:
    [echo] myJni: /home/user/working/eclipse_proj/myJini/build.xml
    [echo] java.library.path = /home/user/bin/jdk1.5.0_03/jre/lib/i386/server:/home/user/bin/jdk1.5.0_03/jre/lib/i386:/home/user/bin/jdk1.5.0_03/jre/../lib/i386:/home/user/working/eclipse_proj/myJini/build:/usr/local/qt/lib:/usr/local/qt/lib:/usr/local/qt/lib:/usr/local/qt/lib:/mnt/bea/p4/src910_150/bea/weblogic90/server/native/linux/i686:/lib:/lib/i686:/usr/lib:/usr/openwin/lib
    [echo] LD_LIBRARY_PATH = /home/user/bin/jdk1.5.0_03/jre/lib/i386/server:/home/user/bin/jdk1.5.0_03/jre/lib/i386:/home/user/bin/jdk1.5.0_03/jre/../lib/i386:/home/user/working/eclipse_proj/myJini/build:/usr/local/qt/lib:/usr/local/qt/lib:/usr/local/qt/lib:/usr/local/qt/lib:/mnt/bea/p4/src910_150/bea/weblogic90/server/native/linux/i686:/lib:/lib/i686:/usr/lib:/usr/openwin/lib
    Hello world :o)
    BUILD SUCCESSFUL
    Total time: 1 second
    References:
    http://public.cabit.wpcarey.asu.edu/janjua/java/jni/
    http://bleaklow.com/blog/archive/000162.html
    http://sourceforge.net/projects/ant-contrib
    http://sourceforge.net/project/showfiles.php?group_id=36177&package_id=28636

    VC++ works just fine.
    I use the IDE rather than command-line processing. I create a "dll" project, and implement the functions defined by running javah.

  • Linux JVM: How to load shared libraries with mutual/circular dependencies

    Hi,
    I am using the API
    System.loadLibrary(String name)
    to dynamically link shared libaries to Linux JVM.
    The shared libraries has complex circular symbol dependencies among them.
    I am not able to load shared libraries due to java.lang.UnsatisfiedLinkError.
    Any ideas on how a number of shared libraries with interdependent realtionships
    could be successfully linked in to the Linux JVM?
    Thanks,
    Soumen.
    Background
    ===========
    Successful execution of native code within Java virtual machine in a
    host platform, has two necessary prerequisites:
    Prerequisite 1: The native code is written to the JNI specification
    Prerequisite 2: The native code is dynamically linked with Java virtual
    machine.
    The second step is achieved via simple Java interface, System.loadLibrary:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#loadLibrary(java.lang.String)
    However, implementation of this interface is highly platform dependent
    in regards to exact nature of dynamic linking process.
    Tests
    =====
    I made three shared libraries libfeatureA.so, libfeatureB.so and libfeatureC.so.
    Feature A and Feature B are mutually dependent on each other (i.e cicular
    dependencies between libfeatureA.so, libfeatureB.so) whereas libfeatureC.so
    has no external dependencies.
    Case 1
    I could link libfeatureC.so with java.
    Case 2
    Java failed to resolve circular dependency between libfeatureA.so, libfeatureB.so
    resulting in linking failure. There may be repackaging workarounds which I have
    not yet explored.
    Java source code
    ================
    class TestLoadLibrary
    static
    System.loadLibrary("featureB");
    System.loadLibrary("featureA");
    System.loadLibrary("featureB");
    public static void main(String[] args)
    System.out.println("In TestLoadLibrary.main()");
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /homes/soumen/work/event/featureB/libfeatureB.so.1.0: /homes/soumen/work/ev B.so.1.0: undefined symbol: featureA_func2
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1737)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1662)
    at java.lang.Runtime.loadLibrary0(Runtime.java:817)
    at java.lang.System.loadLibrary(System.java:986)
    at TestLoadLibrary.<clinit>(TestLoadLibrary.java:5)

    The use of "dlopen() application programming" to achieve dynamic link closure works if there are
    no circular dependencies. For example, I have the following dependency:
    libfeatureD.so ==> libfeatureC.so
    Even if I call Java APIs in correct dependency order, i.e.,
    System.loadLibrary("featureC");
    System.loadLibrary("featureD");
    there would be java.lang.UnsatisfiedLinkError for call System.loadLibrary("featureD").
    Now, I have a JNI method implementation, which makes native API call in same dependency order:
    dlopen("libfeatureC.so", RTLD_LAZY|RTLD_GLOBAL);
    dlopen("libfeatureD.so", RTLD_LAZY|RTLD_GLOBAL);
    and now System.loadLibrary calls succeed. Note that I had to set environment
    variable LD_LIBRARY_PATH so that dlopen call would find libraries to load.
    In other words, from a JNI programming point of view, "linking chasm" has been crossed.
    I am looking at circular dependency issue, i.e.,
    libfeatureA.so <==> libfeatureB.so
    There may be library repackaging workaround.
    If anybody knows any workaround, please post.
    -Soumen Sarkar
    JNI code
    ========
    #include <jni.h>
    #include "TestLoadLibrary.h"
    #include <stdio.h>
    #include <string.h>
    #include <dlfcn.h>
    JNIEXPORT void JNICALL Java_TestLoadLibrary_libLoadNative
    (JNIEnv * jenv, jclass class, jobjectArray libNames)
    printf("native: In TestLoadLibrary.libLoadNative()\n");
    char linuxLibName[1024];
    jsize idx = 0;
    jsize nLibs = (*jenv)->GetArrayLength(jenv, libNames);
    for(idx = 0; idx < nLibs; ++idx)
    /* obtain the current object from the object array */
    jobject myObject = (*jenv)->GetObjectArrayElement(jenv, libNames, idx);
    /* Convert the object just obtained into a String */
    const char libName = (jenv)->GetStringUTFChars(jenv,myObject,0);
    strcpy(linuxLibName, "lib");
    strcat(linuxLibName, libName);
    strcat(linuxLibName, ".so");
    printf("\nnative: Trying to open lib with name %s\n", linuxLibName);
    void* handle = dlopen(linuxLibName, RTLD_LAZY|RTLD_GLOBAL);
    if(handle == 0)
    fputs ("\nnative: Could not load lib\n", stderr);
    fputs (dlerror(), stderr);
    else
    printf("\nnative: Loaded lib %s\n", linuxLibName);
    /* Free up memory to prevent memory leaks */
    (*jenv)->ReleaseStringUTFChars(jenv, myObject, libName);
    return;

  • System.loadLibrary() for libraries with dependencies?

    Hi,
    Given an application that depends upon JNI library "jniLibrary.dll" which in turn depends upon "otherLibrary.dll" when one invokes System.loadLibrary("jniLibrary") two things happen:
    1) Under normal applications, the system will complain it can't find dependent library "otherLibrary" because it isn't in the PATH. You can work around this by invoking System.loadLibrary("otherLibrary") first but I've been told System.loadLibrary() is only meant for JNI libraries and invoking it on any other library is not guaranteed to work.
    2) Under Webstart applications, if you try loading "otherLibrary" first it will fail because of http://bugs.sun.com/view_bug.do?bug_id=6191612
    There doesn't seem to be a "correct" way to fix this problem under all environments. Can someone please explain what the application should be doing in this case to ensure that "jniLibrary" loads correctly? Modifying the PATH is not an option because of the Webstart use-case (besides which, users don't appreciate it).
    Thank you,
    Gili

    2) Under Webstart applications, if you try loading "otherLibrary" first it will fail because of http://bugs.sun.com/view_bug.do?bug_id=6191612
    That is a little weird.
    Far as I know you can't stop the OS from loading dependent libraries. Thus when the OS attempts to load library B, if it explicitly depends on library A then the OS (not java) will attempt to load it.
    Now if the OS can't load it then it will throw a system exception.
    So the only way that bug makes sense is if the jws is parsing the shared library to find dependencies and then checking the process space for them and throwing if they are not there. Seems like a lot of work. When it could just load it. (But maybe it is actually loading them from another source)
    At any rate that isn't what that bug says. It says that if you don't in fact load library A, then it will fail. So load it.I filed that bug so I'll try filling in the holes.
    Problem 1: Webstart uses a custom ClassLoader that only unpacks DLLs from their JAR file on-demand. So if you try loading A the class-loader will extract it from the JAR file into a temporary directory and invoke win32's LoadLibrary on it. Of course it will never find any dependent libraries because they haven't been extracted.
    Problem 2: If you use a manifest file (also packed in the JAR file) you have no way to tell Webstart to unpack it alongside the DLL. Loading the DLL without it will fail.
    If I remember correctly (this is off the top of my mind) you can work around problem #1 by loading the dependent libraries first but this won't work if you have circular dependencies. You can work around problem #2 by embedding the manifest file into the DLL file. I'm fairly sure I tried working around #1 as mentioned but it still broke (maybe another problem beyond circular dependencies that I don't recall).
    This is a lot of cryptic work one needs to do just to get things up and running. We're spending most of our time trying to hack the JVM to do what we want instead of it doing what we mean (the spirit of System.loadLibrary()).

  • How to dynamicaly link multiple shared objects (.so files) using JNI

    Hi all,
    I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file).
    Can someone suggest me any solution for the same? I am a Java developer and don't have much knowledge about the C language.
    Any suggestion will be highly appreciated.

    jeet420 wrote:
    Hi all,
    I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file). That is not a Java/JNI problem.
    A shared library either uses an explicit link or dynamic link to other libraries.
    If the first then the OS will fail the load of the library if it can't find the dependency.
    If the second then the implementation (the developer) is responsible for correctly dealing with the problem.
    Again none of the above has anything to do with Java nor JNI.
    Nothing in Java nor JNI will help you to figure out the problem nor manage it.
    Two solutions.
    1. Be very careful in manually managing the laydown via an installer of all of the required libraries.
    2. Write code to verify that all libraries are found by the OS. This however still require manual steps as you must explicitly name the shared libraries in some way.
    ... and don't have much knowledge about the C language.Not a good situation. JNI assumes that you have quite a bit of knowledge about C and/or C++.

  • Problem with JNI and Tomcat (and threads???)

    Howdy,
    Here is the issue - I would like some help on HOW to debug and fix this problem:
    2 test use cases -
    1)
    a)User goes to Login.jsp, enters user and password
    b) User submits to LoginServlet
    c) login calls JNI code that connects to a powerbuilder(Yes I know this is ugly) PBNI code module (this is a .dll) that authenticates the user with the database
    d) the servlet then redirects to another .jsp page
    e) user then submits to LogoutServlet - also a JNI call to a powerbuilder PBNI code module
    f) REPEAT STEPS a-e over a few times (inconsistent) and then the call to the JNI code hangs
    2)
    a) users does NOT goto Login.jsp, but rather calls LoginServlet and passes the userid and password as GET parms
    b) user does NOT get redirected to a page (redirect code commented out)
    c) user calls LogoutServlet
    d) repeat steps a-c at will and no failure, no hanging
    The only difference is that in case 1 (with JSP), there is a redirect and it afffected the JNI call by haniging inside JNI code.
    In case 2 (without JSP) there is still a JNI call, but it does not hang. In addition, when it hangs and I stop Tomcat, the logs show cleanup entries that say:
    Oct 19, 2004 9:17:09 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Oct 19, 2004 9:17:10 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Oct 19, 2004 9:17:11 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Is this a threading issue in Tomcat???
    On would assume that the JNI code is not cleaning up after itself, but I don't believe this is the case,
    and even if it was, why would I get the tomcat log cleanup entries above???
    What do those cleanup entries imply about the state of Tomcat????

    hi ,
    I met the same problem this morning, and searched the www.google.com in order to solve it, as a result, your article was shown on my screen. :)
    Till now I have read some technical information and solved my problems. Maybe the solution be useful to you:
    ==============================
    error message : (Environment : Tomcat 5, Windows 2003, Mysql5)
    2006-3-29 11:53:48 org.apache.catalina.core.StandardWrapper unload
    message: Waiting for 2 instance(s) to be deallocated
    ==============================
    cause: the number of connection to database exceeded.another word,too many connections.
    ==============================
    solution: close the connection when it becomes useless for your program. :)
    ==============================
    ps. Sorry for my weak English . hehe ....

  • Couldn't Load DLL and Call JNI in Portal Servlet !!!

    Hello,
    I'm trying to write a small test servlet in portal which will call functions in a DLL using JNI. Here is my source code. I put my DLL in \Window\system32, usr/sap/J2E/JC01/j2ee/os_libs, even included into my portal project \PORTAL-INF\lib. But everytime when I try to preview my page, I got the following error and I couldn't find the log file specified in the error message. Please help me out. Thanks a lot!
    Portal Runtime Error
    An exception occurred while processing a request for :
    iView : N/A
    Component Name : N/A
    MyTestDLL.
    Exception id: 12:25_23/12/06_0029_11241950
    See the details for the exception ID in the log file
    Source Code:
    import com.sapportals.portal.prt.component.*;
    public class CIViewTest extends AbstractPortalComponent
         public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
              response.write("Hello From Java Servlet!!!\n");
         static {
              try {
                   Runtime.getRuntime().loadLibrary("MyTestDLL");
    // I've also tried System.LoadLibrary("MyTestDLL");
              } catch (UnsatisfiedLinkError ule) {
                   throw ule;

    Nobody used JNI in Portal Servlet??? Please advice. Thanks!

  • 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
    Lars

    I 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

  • 64-bit JNI C++ to JAVA invocation multiple threads classloader problem

    Hi ALL,
    I have a C++ app that invokes Java classes on 64-bit Solaris 10 with 64-bit JVM.
    Here is the problem:
    The native non-main (not the thread that initializes the JVM) threads would not be able to find any user-define class.
    Here are the symptoms and observations:
    1. JNIEnv::ExceptionDescribe() showed the following StackOverflowError:
    Exception in thread "Thread-0" java.lang.StackOverflowError
            at java.util.Arrays.copyOf(Arrays.java:2734)
            at java.util.Vector.ensureCapacityHelper(Vector.java:226)
            at java.util.Vector.addElement(Vector.java:573)
            at java.lang.ClassLoader.addClass(ClassLoader.java:173)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)2. The "main thread" that instantiates the JVM has no problem finding and loading any class or method
    3. But the other threads (non-main threads) would not be able to find the user-defined classes unless the classes were already loaded by the main thread.
    4. The non-main threads can find the "standard" java classes with no problem
    5. The same app ran fine on 32-bit system.
    6. Except for the JVM reference is global, each thread acquired JNIEnv by either GetEnv() or AttachCurrentThread().
    Any idea why it is a problem with 64-bit?
    I have the sample program to reproduce this issue in this thread: http://forums.sun.com/thread.jspa?messageID=10885363&#10885363. That was the original thread I raised but I have narrowed it down to a more concrete scenario. That's why I am creating this new thread. I hope this does not break any rule on this forum. If it does, I apologize.
    I really appreciate it if anyone can provide any help/suggestion.
    Regards,
    - Triet

    Here is the sample program. Again, this works on 32-bit but not 64-bit.
    #include <string>
    #include "jni.h"
    #include "TestThread.h"
    static JavaVM *g_pjvm = NULL;  /* denotes a Java VM */
    static JNIEnv *g_penv = NULL;  /* pointer to native method interface */
    void initJVM(char** jvmOptions) {
        printf("RJniTest init starts...\n");
        JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
        JavaVMOption* poptions;
        int optionLen = 0;
        while (jvmOptions[optionLen]) {
            optionLen++;
        printf("RJniTest::init len=%d\n", optionLen);
        if (optionLen > 0) {
            printf("RJniWrapper::init jvmOptions\n");
            poptions = new JavaVMOption[optionLen];
            //poptions[0].optionString = "-Djava.class.path=/usr/lib/java";
            int idx = 0;
            while (jvmOptions[idx]) {
                poptions[idx].optionString = jvmOptions[idx];
                idx++;
        printf("RJniTest::init vm_args: version(%x), nOptions(%d)\n",
                JNI_VERSION_1_6, optionLen);
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = optionLen;
        vm_args.options = poptions;
        vm_args.ignoreUnrecognized = JNI_FALSE;
        // load and initialize a Java VM, return a JNI interface
        // pointer in env
        printf("RJniTest::init creates JVM\n");
        JNI_CreateJavaVM(&g_pjvm, (void**)&g_penv, &vm_args);
        printf("RJniTest init ends\n");
    void findClass(const char* classname) {
        static const char* fname = "justFindClasses";
        printf("%s: findClass: %s\n", fname, classname);
        JNIEnv* jenv;
        jint ret = g_pjvm->GetEnv((void**)&jenv, JNI_VERSION_1_6);
        if (ret == JNI_EDETACHED) {
            ret = g_pjvm->AttachCurrentThread((void**)&jenv, NULL);
            if (ret != JNI_OK || jenv == NULL) {
                printf("%s: get env error: ret=%d\n", ret, fname);
            } else {
                printf("%s: got new env\n", fname);
        } else if (ret == JNI_OK) {
            printf("%s: env already there\n");
        jclass classref;
        classref = jenv->FindClass(classname);
        if (classref == NULL) {
            printf("%s: %s class not found!\n", fname, classname);
            if (jenv->ExceptionOccurred()) {
                jenv->ExceptionDescribe();
                jenv->ExceptionClear();
        printf("%s: found class: %s\n", fname, classname);
    class RJniTestThread : public TestThread {
    public:
        void threadmain();
    void RJniTestThread::threadmain() {
        printf("RJniTestThread::threadmain: Starting testing\n");
        findClass("org/apache/commons/logging/Log");
        findClass("java/util/List");
        printf("RJniTestThread::threadmain: done.\n");
    int main(int argc, char** argv) {
        char **jvmOptions = NULL;
        printf("RJniTestDriver starts...\n");
        if (argc > 1) {
            jvmOptions = new char*[argc];
            for (int i = 0; i < argc ; i ++) {
                jvmOptions[i] = argv[i + 1];
            jvmOptions[argc - 1] = NULL;
        } else {
            int size = 8;
            int i = 0;
            jvmOptions = new char*[size];
            jvmOptions[i++] = (char*) "-Djava.class.path=<list of jar files and path here>";
            jvmOptions[i++] = (char*) "-Djava.library.path=/sandbox/mxdev/3rdparty/java/unix/jdk1.6.0_14/jre/lib/sparc";
            jvmOptions[i++] = (char*) "-Djava.compiler=NONE";
            jvmOptions[i++] = (char*) "-verbose:jni";
            jvmOptions[i++] = (char*) "-Xcheck:jni";
            jvmOptions[i++] = NULL;
        printf("init JVM\n");
        initJVM(jvmOptions);
        // UNCOMMENT HERE
        // findClass("org/apache/commons/logging/Log");
        // findClass("java/util/List");
        // UNCOMMENT END
        printf("start test thread\n");
        RJniTestThread testThread;
        ThreadId tid = testThread.launch();
        printf("wait for test thread\n");
        int ret = pthread_join(tid, NULL);
        printf("RJniTestDriver ends\n");
    }

Maybe you are looking for

  • View creation very slow - not materialized view

    I have a view creation script which is running in a fraction of a second in the dev environment but takes over an hour to run in the test environment. The test environment is off-site, so I have no direct access to it. It does have a lot more data in

  • How do i install windows on my mac mini

    The newer Mac mini's don't have an optical drive. I have a Samsung external dvd drive but i don't know if i need to have the "Superdrive" and will mine work when installing.

  • Can we use concatenate in where clause of a select query

    I have a select query as follows....     SELECT ebeln ebelp belnr vgabe bwart DMBTR                              FROM ekbe                              INTO TABLE i_ekbe                              FOR ALL ENTRIES IN i_blck                          

  • How to view  file in EBS R12

    Hi, I have a report output file report1.pdf coming from windows. I ftp it to our EBS R12 linux server to the desired location. How can I view it using the "view request" of the EBS CM? Thanks a lot

  • Aperture 3 keeps making me enter serial number

    This is getting to be a frustrating glitch. On a fairly regular basis, regular enough that I now have my serial number of a post-it, Aperture prompts me to enter my name and serial number when launched. Having done so it then promptly hangs, I have t