Problem finding native methods in java packages

Hi,
I have a java class which uses some native methods written in OCamL. I wrote a C file which calls the OCamL code, and created the corresponding shared library using the jni. I then tested my java file and everything works fine, I can nicely call the OCamL functions. However, I need this java file to be included in a package, but whenever I add the line:
package somepackage;
on top of the java code, my java file simply doesn't seem to find the C and OCamL implementation anymore :
javac -cp :./path/of/somepackage
-Djava.library.path=/full/path/of/somepackage MyProgram args
Exception in thread "main" java.lang.UnsatisfiedLinkError:functionName
at somepackage.ClassName.functionName(NativeMethod)
I have of course put everything (java, C, .h , libsomelibrary.so, and OCamL files) in a directory called somepackage, and written another java file which creates an instance of the first one from outside the package, imports the package, and calls its methods in main(). It just doesn't work anymore.
I then added a simple hello-world function (not C nor OCamL code) to the java file inside the package. And when invoked from outside, it worked. Question is then... Am I forgetting something to be done, in order to get C and CamL files efectively included in the java package (same as "package somepackage;" in C or OCaml, perhaps)??? Why isn't the java file able to find them inside its very own directory (having into account that without the package definition it worked well)?
Thanks,
PS Im using jsdk 1.4.1 on lunyx redhat 8.0

Did you change the name of the function in the library, too?
If the function name was
"Java_YourClass_functionname",
it should be now
"Java_path_to_your_package_YourClass_functionname".

Similar Messages

  • Calling native methods in a package

    Hi!
    We have a problem when calling native methods in a class which is in a package. As you can see from the code below we have a class making an instance of a class<testBando> which makes a instance of another class<Bando> which contains the native methods. When running the program we get the error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: initialize
    at test2.Bando.initialize(Native Method)
    at test.testBando.<init>(testBando.java:10)
    at Main.main(Main.java:5)
    When we take the class that calls the native methods out of any package every thing works fine! Can you not call native methods inside a package or what are we doing wrong?
    // testBando.java
    package test;
    import test2.*;
    public class testBando {
    Bando b;
    public testBando() {
         b = new Bando();
         b.initialize();
    // Bando.java
    package test2;
    public class Bando {
    public native void initialize();
    static {
         System.loadLibrary("bando");
    // Main.java
    import test.*;
    public class Main {
    public static void main(String[] args) {
         new testBando();

    I suspect that your problem is that you have not
    regenerated the signature when you placed the native
    method's object in a package. Or same result but different sourc:
    -package name was changed and it wasn't regen'd
    -javah was run incorrectly (which gens the signatures with no package name.)

  • How can I return in a native method a Java type?

    Hi,
    i want to return in the native methode ja Java type java.awt.Dimension!
    How can I do this?
    Java code:--------------------------------------------------------------------------------
    public native java.awt.Dimension getSize()
    generating the JNI header file
    JNI header code:--------------------------------------------------------------------------------
    JNIEXPORT jobject JNICALL Java_Video_getSize(JNIEnv *, jobject)
    my c function looks like this
    code:--------------------------------------------------------------------------------
    JNIEXPORT jobject JNICALL Java_Video_getSize(JNIEnv *env, jobject obj)
    return ???????
    how can I return in C an object like jawa.awt.Dimension?
    Thx
    Ronny

    Here is my 2 cents for a way we pass data between Java and C via the Java Native Interface. This excerpt is an example of passing an int value through a locally created Integer wrapper class, which must be adapted for local use. Note that because of the wrapper, return values are not needed.
    1. Create the Java class file.
    * This class encapsulates a Java <CODE>int</CODE> primitive.
    * This class was created to allow programmers to change
    * the value of an existing integer object without being
    * forced to create a new object (as is the case with the
    * Java Integer object).
    public class LocalInteger
         private int     value;
         * Creates a LocalInteger object and initializes
         * it to <I>0</I> (the default in Java).
         public LocalInteger ()
              super ();
         * Creates a LocalInteger object and initializes
         * it using the given <I>int</I> value.
         * @param i Integer value to use in initializing
         * the object.
         public LocalInteger (int i)
              super ();
              value = i;
         * Gets the value of the object.
         * @return The value of the object.
         public int getValue ()
              return (value);
    2. Create the jni header file.
    DLL_EXTERN void jni_GetValue_from_LocalInteger(int* LocalInteger, JNIEnv *env, jobject thisLocalInteger);
    3. Create the C file.
    /*start of jni header****************************************
    *NAME/TITLE:       jni_GetValue_from_LocalInteger
    *DESCRIPTION:      This routine copies the integer value
    * from the Java LocalInteger object to the
    * C 'int' variable.
    *CALLING SEQUENCE: jni_GetValue_from_LocalInteger (LocalInteger,
    * env,
    * thisLocalInteger)
    *PARAMETERS:
    * Type Name I/O Description
    * int * LocalInteger I/O C variable
    * JNIEnv * env I JNIEnv pointer
    * jobject thisLocalInteger I Java object
    *RETURN:           N/A
    **end of header*********************************************/
    /* ********************** BEGIN CODE ********************** */
    DLL_EXPORT
    void jni_GetValue_from_LocalInteger(int* LocalInteger, JNIEnv *env, jobject thisLocalInteger)
         LocalInteger = (int) (env)->GetIntField(env, thisLocalInteger, LocalInteger_Value);

  • Why I can't call my native method from my package?

    it is fine if my java code didn't complied into a package.
    But if I complied my java code as a package, and call its native method outside. It give me "UnsatisfiedLinkError". And can not find my method. It is indeed the method is inside.
    Thank a lot any helps. Email me on [email protected]

    I have found that javah does not generate the correct JNI function names when the native function is in a class that is within a Java package. The net result is an Unsatisfied link error.
    The JNI function name must be included in the package name. The naming is a bit complicated and that's why javah should be used, except in this case it does not work. I can't quite remember exactly how it works, something like adding in packagename_1 into the JNI name. The SWIG tool (http://www.swig.org) does generate the correct names when using packages. It is a tool which takes C or C++ header files and generates the JNI and Java classes for you so that you can call C/C++ code from Java. Once you have installed SWIG and run 'make check', have a look in the directory Examples/test-suite/java for the JNI naming for packages. I'll try remember to post the exact naming if you don't want to install SWIG.

  • Problem in addBatch method in java.sql.Statement Interface

    Hi
    I am facing a problem java.lang.UnsupportedOperationException when using addbatch() method of java.sql.Statement Interface.
    Please suggest solutions.
    Thanks
    nsgindia

    Your JDBC driver doesn't support batch operation, try another driver(not all databases support batch'es eg MySQL)

  • Not able to find validateUser method in java.io.*

    I have a servlet code that has "import java.io.*"
    The class uses validateUser method but files in the lib folder is not able to find this method. Using Eclipse and thru IDE I browsed JAR file and method does not exists. Using Java 1.5.01
    Please advice.

    What object does it call the method from?
    If there is no object pre-fixed to the method name then the method belongs to the class which calls it. If you don't see it in the class you are working on, then check all of the class' parents.
    If it doesn't exist there then contact whoever you stole the code from and ask them were the method is supposed to be.

  • Delay in executing Native Methods in Java

    Hi,
    I have the following code in my Java application.
    After calling, there is a long delay in actual execution of the native methods call. I noticed, when the program is about to terminate, then the ouput is coming from the native method.
    Here is the sample code & output of the program:
    Source :
    ======
    for (int i=0; i<5; i++) {
    System.out.println("Before : " + out);
    new SchedulerTimer().displayHelloWorld();
    System.out.println("After");
    Output:
    =====
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    After
    Hello world!
    Hello world!
    Hello world!
    Hello world!
    Hello world!
    Expected :
    ========
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    Hello world!
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    Hello world!
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    Hello world!
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    Hello world!
    After
    Before : Agent : Tue Nov 09 20:51:50 GMT+05:30 2004
    Hello world!
    After
    (In the above output, "Hello world!" is the output expected from the native method)
    (displayHelloWorld - is the native method)
    Thanks,

    Ivar's guess is probably right.
    If you use
    cout << "Hello world!\n";
    in a C++ program most probably the output will be buffered.
    Even
    cout << "Hello world!" << endl;
    is not a total guarantee for flushing the buffer, although endl promises to do that. Check your C++ documentation.

  • How to find classes in a java package

    i am writing a java IDE. i want to extract all class names from a java package eg. java.lang (through coding). how can i do that.
    Thanks in advance

    File file = new File("path to your jar file");
    JarFile jf = new JarFile(file);
    Enumeration e = jf.entries();
    ZipEntry ze = null;
    while(e.hasMoreElements()){
    ze = (ZipEntry) e.nextElement();
    ze.toString(); // gives you the file name
    you have to understand java.util.jar java.util.zip packages for working with jar/zip files.
    Hope this helps

  • HELP!!!! Problems with Native methods

    Hi,
    I am a student of computer Science. I am trying to call from Java a function written in C in which I use the "free" function to release memory space, but when I run the program it shows me a NullPointerException. I have tried to avoid using the "free" function but the program takes all of the memory and shows me an OutOfMemoryException so I need to use that function.
    If someone knows how to solve my problem, please, tell me how.
    Thank you very much!
    P.D.: Excuse my level of English. I am Spanish.

    Please send some code!
    Probably you should use DeleteLocalRef instead of free.

  • NoClassDefFoundError problems -native method

    hi all,
    i've got a wierd problem... when i try to run a java appln ( for instance curl.java whose class is stored in a jar file) without giving a proper argument say like:
    java XX.RR.YY.curl
    a message prompts me to input a valid argument :
    Usage: XX.RR.YY.hyd <options>
    but when i try to run the same program - this time giving it a valid argument- like :
    java XX.RR.YY.curl -curltest.xml
    it spews out the following error messages along many others
    Exception in thread "main" java.lang.NoClassDefFoundError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:130)
    my point is why does java fail to find the class when i give it a valid argument and not when i do not give it any.
    thanks in advance

    exactly ... my java program has a similar code in it
    regarding the arg checking .
    so it does mean that java had found my appln
    class(yay! my classpath is right) and had run thru a
    few lines of code to get to the point where it
    realized it needed some arguments and so gently asked
    me supply an argument (a valid filename in my case)...Did you write this code? Did you put in the line where it displays the usage?
    so the next thing i do is run the same command java
    xx.xx.xx -curltest.xml ( i've supplied a valid
    argument this time ) ... the result :
    Exception in thread "main"
    java.lang.NoClassDefFoundError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:130)
    why did java fail to grab my appln class this time -
    in contrast to the first time where it found the class
    file w/o any problems. Try just using "java xx.xx.xx curltest.xml" (without the '-').

  • In the Packet not able to find the native method

    I have native method callSucJava , This method when called from the java file independently (without it being part of the package ) works fine.
    But when i copy the same class with the native method defined into the package and include the java file with the native method in the package , it gives the following error
    java.lang.UnsatisfiedLinkError: callSucJava
    Which means it is not able to locate the neative methos in the library . It is ofcourse able to find the library. But as this method is present in the library , and syntactically it is correct as it works fine when being run independently.
    Any help would be appreciated.
    thanks

    In your old library there shoud be the function
    JNIEXPORT void JNICALL
    Java_callSucJava(JNIEnv *, jobject) {
    You have to change it to:
    JNIEXPORT void JNICALL
    Java_your_package_callSucJava(JNIEnv *, jobject) {

  • At java.lang.Throwable.fillInStackTrace(Native Method)

    Hello,
    I have a Jsp,which has a hyper link to another Jsp.Some times very rarely i get this error when i click on the
    link.
    java.lang.RuntimeException: IOException occured
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.lang.RuntimeException.<init>(Compiled Code)
    at weblogic.servlet.internal.ServletOutputStreamImpl.write(Compiled Code)
    at weblogic.servlet.internal.WLOutputStreamWriter.flushBuffer(Compiled Code)
    at weblogic.servlet.internal.WLOutputStreamWriter.write(Compiled Code)
    at weblogic.servlet.internal.WLOutputStreamWriter.write(Compiled Code)
    at java.io.Writer.write(Compiled Code)
    at weblogic.servlet.jsp.JspWriterImpl.print(Compiled Code)
    at examples.jsp._pfsonline._https._showhide.__sso_showhide_cur._jspService(Compiled Code)
    at weblogic.servlet.jsp.JspBase.service(Compiled Code)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Compiled Code)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Compiled Code)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Compiled Code)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Compiled Code)
    at weblogic.servlet.internal.ServletContextManager.invokeServlet(Compiled Code)
    at weblogic.socket.MuxableSocketHTTP.invokeServlet(Compiled Code)
    at weblogic.socket.MuxableSocketHTTP.execute(Compiled Code)
    at weblogic.kernel.ExecuteThread.run(Compiled Code)
    can some one tell me when does this happen.Is it something to do with the configuration.
    Thanks
    Shashi

    Did you ever find out the answer to this question?
    I have been getting a similar error. My page draws
    fine, but I get an occasional error:
    java.lang.RuntimeException: IOException occured
    at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:178)
    at weblogic.servlet.internal.WLOutputStreamWriter.flushBuffer(WLOutputStreamWriter.java:139)
    at weblogic.servlet.internal.WLOutputStreamWriter.write(WLOutputStreamWriter.java:104)
    at weblogic.servlet.internal.WLOutputStreamWriter.write(WLOutputStreamWriter.java:111)
    at java.io.Writer.write(Unknown Source)
    at weblogic.servlet.jsp.JspWriterImpl.print(JspWriterImpl.java:155)
    at jspc._admin._offering.__offering_intro._jspService(__offering_intro.java:433)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:120)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:138)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:941)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:905)
    at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:269)
    at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:391)
    at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:273)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
    Let me know if you get any answers.
    Best,
    JL
    [email protected]

  • Java.lang.OutOfMemoryError(Native Method)

    Hello Everybody,
    We hava a java.lang.OutOfMemoryError,the problem weblogic server installed in windows 2003 x64,weblogic version 9.2 MP1,sun jdk 1.5.0_22 32bit,the memory configuration below:
    set MEM_ARGS=-server -Xms1024m -Xmx1024m -verbose:gc -Xloggc:%SERVER_NAME%_GC.log -XX:SurvivorRatio=3 -XX:NewSize=512M -XX:MaxNewSize=512M -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+HeapDumpOnCtrlBreak -XX:+HeapDumpOnOutOfMemoryError
    if "%JAVA_VENDOR%"=="Sun" (
         set MEM_ARGS=%MEM_ARGS% %MEM_DEV_ARGS% -XX:MaxPermSize=512m
    The error in log below:
    ####<2013-2-16 上午11时08分15秒 CST> <Error> <Kernel> <CWGK-APP-2> <node2> <[STANDBY] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1360984095564> <BEA-000802> <ExecuteRequest failed
    java.lang.OutOfMemoryError.
    java.lang.OutOfMemoryError
         at java.io.RandomAccessFile.readBytes(Native Method)
         at java.io.RandomAccessFile.read(RandomAccessFile.java:315)
         at weblogic.diagnostics.archive.FileUtils.readFile(FileUtils.java:46)
         at weblogic.diagnostics.archive.filestore.FileIndexMetaInfo.buildIndex(FileIndexMetaInfo.java:403)
         at weblogic.diagnostics.archive.filestore.FileIndexMetaInfo.buildIndex(FileIndexMetaInfo.java:319)
         at weblogic.diagnostics.archive.filestore.FileDataArchive.computeFullIndices(FileDataArchive.java:521)
         at weblogic.diagnostics.archive.filestore.FileDataArchive.computeIndices(FileDataArchive.java:629)
         at weblogic.diagnostics.archive.filestore.FileDataIndexer$IndexCommand.run(FileDataIndexer.java:199)
         at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    >
    How can i solution the problem?
    Please help.

    Need more log information to diagnose it.
    Kinds,
    Gabriel Abelha

  • Problem using a jar file : java.lang.ClassNotFoundException: ApiConn

    Hi everyone.
    i am running a form that use a bean_area to call a jar.
    but i am getting this error, thanks in advnce for any tip.
    Java Plug-in 1.6.0_33
    Using JRE version 1.6.0_33-b05 Java HotSpot(TM) Client VM
    User home directory = C:\Users\user1
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    java.lang.ClassNotFoundException: ApiConn
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at oracle.forms.handler.UICommon.instantiate(Unknown Source)
         at oracle.forms.handler.UICommon.onCreate(Unknown Source)
         at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
         at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
         at oracle.forms.engine.Runform.processMessage(Unknown Source)
         at oracle.forms.engine.Runform.processSet(Unknown Source)
         at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
         at oracle.forms.engine.Runform.onMessage(Unknown Source)
         at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$000(Unknown Source)
         at java.awt.EventQueue$1.run(Unknown Source)
         at java.awt.EventQueue$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue$2.run(Unknown Source)
         at java.awt.EventQueue$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Dumping class loader cache...
    Live entry: key=http://192.168.10.100:7778/forms/java/,frmall.jar,siberia_jpg.jar,ApiConn.jar,Hasher.jar,ReadCommand.jar,WriteCommand.jar,libAPI.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://192.168.10.100:7778/forms/java/-threadGroup,maxpri=4]
    Done.
    in my form i have created a bean_area and used as implementation class :ApiConn
    in my formsweb.cfg i used this configuration: archive=frmall.jar,siberia_jpg.jar,ApiConn.jar,Hasher.jar,ReadCommand.jar,WriteCommand.jar,libAPI.jar
    in my forms/java i have placed my jar files listed in the frmall.jar
    i guess i am missing something but i dont know what it is.
    here is my ApiConn.java from wich i generate my jar file:
    package libAPI;
    * This contains connection. Everything should be here,
    * should operate with this class only
    import java.io.*;
    import java.net.*;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author janisk
    public class ApiConn extends Thread {
    private Socket sock = null;
    private DataOutputStream out = null;
    private DataInputStream in = null;
    private String ipAddress;
    private int ipPort;
    private boolean connected = false;
    private String message = "Not connected";
    private ReadCommand readCommand = null;
    private WriteCommand writeCommand = null;
    private Thread listener = null;
    LinkedBlockingQueue queue = new LinkedBlockingQueue(40);
    * Constructor of the connection class
    * @param ipAddress - IP address of the router you want to conenct to
    * @param ipPort - port used for connection, ROS default is 8728
    public ApiConn(String ipAddress, int ipPort) {
    this.ipAddress = ipAddress;
    this.ipPort = ipPort;
    this.setName("settings");
    * State of connection
    * @return - if connection is established to router it returns true.
    public boolean isConnected() {
    return connected;
    public void disconnect() throws IOException{
    listener.interrupt();
    sock.close();
    private void listen() {
    if (this.isConnected()) {
    if (readCommand == null) {
    readCommand = new ReadCommand(in, queue);
    listener = new Thread(readCommand);
    listener.setDaemon(true);
    listener.setName("listener");
    listener.start();
    * to get IP address of the connection. Reads data from socket created.
    * @return InetAddress
    public InetAddress getIpAddress() {
    return sock == null ? null : sock.getInetAddress();
    * returns ip address that socket is asociated with.
    * @return InetAddress
    public InetAddress getLocalIpAddress() {
    return sock == null ? null : sock.getLocalAddress();
    * Socket remote port number
    * @return
    public int getPort() {
    return sock == null ? null : sock.getPort();
    * return local prot used by socket
    * @return
    public int getLocalPort() {
    return sock == null ? null : sock.getLocalPort();
    * Returns status message set up bu class.
    * @return
    public String getMessage() {
    return message;
    * sets and exectues command (sends it to RouterOS host connected)
    * @param s - command will be sent to RouterOS for example "/ip/address/print\n=follow="
    * @return
    public String sendCommand(String s) {
    return writeCommand.setCommand(s).runCommand();
    * exeecutes already set command.
    * @return returns status of the command sent
    public String runCommand() {
    return writeCommand.runCommand();
    * Tries to fech data that is repllied to commands sent. It will wait till it can return something.
    * @return returns data sent by RouterOS
    * @throws java.lang.InterruptedException
    public String getData() throws InterruptedException {
    String s = (String) queue.take();
    return s;
    * returns command that is set at this moment. And will be exectued if runCommand is exectued.
    * @return
    public String getCommand() {
    return writeCommand.getCommand();
    * set up method that will log you in
    * @param name - username of the user on the router
    * @param password - password for the user
    * @return
    public String login(String name, char[] password) {
    this.sendCommand("/login");
    String s = "a";
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #1";
    if (!s.contains("!trap") && s.length() > 4) {
    String[] tmp = s.trim().split("\n");
    if (tmp.length > 1) {
    tmp = tmp[1].split("=ret=");
    s = "";
    String transition = tmp[tmp.length - 1];
    String chal = "";
    chal = Hasher.hexStrToStr("00") + new String(password) + Hasher.hexStrToStr(transition);
    chal = Hasher.hashMD5(chal);
    String m = "/login\n=name=" + name + "\n=response=00" + chal;
    s = this.sendCommand(m);
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #2";
    if (s.contains("!done")) {
    if (!s.contains("!trap")) {
    return "Login successful";
    return "Login failed";
    @Override
    public void run() {
    try {
    InetAddress ia = InetAddress.getByName(ipAddress);
    if (ia.isReachable(1000)) {
    sock = new Socket(ipAddress, ipPort);
    in = new DataInputStream(sock.getInputStream());
    out = new DataOutputStream(sock.getOutputStream());
    connected = true;
    readCommand = new ReadCommand(in, queue);
    writeCommand = new WriteCommand(out);
    this.listen();
    message = "Connected";
    } else {
    message = "Not reachable";
    } catch (UnknownHostException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    } catch (IOException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    }

    I need your help again, i think this is a minor thing.
    i have compiled the class file that i needed and i signed it too. but now it is giving me a new error and need your tip.
    here is the java console loyout and my java file ((i think here is the problem in java file, something must be missing)).
    thanks in advance for any help.
    Java Plug-in 10.17.2.02
    Using JRE version 1.7.0_17-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Administrator
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    network: Connecting http://192.168.10.100:7778/forms/lservlet;jsessionid=c0a80a6430d6e191eded93774f2f8d1bed73056e66ef.e3mObhiMbxeKe34PahiKbx4Nbh90n6jAmljGr5XDqQLvpAe with proxy=DIRECT
    security: Validate the certificate chain using CertPath API
    security: The certificate hasnt been expired, no need to check timestamping info
    security: Cannot find jurisdiction list file
    security: The CRL support is disabled
    security: The OCSP support is disabled
    security: This OCSP End Entity validation is disabled
    security: Checking if certificate is in Deployment denied certificate store
    security: Checking if certificate is in Deployment permanent certificate store
    basic: updateValidationResultsForApplet update
    cache: Mark prevalidated: http://192.168.10.100:7778/forms/java/ApiConn.jar true tm=1363335797289 cert=1371107987000
    basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
    java.lang.InstantiationException: oracle.forms.siberia.ApiConn
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at oracle.forms.handler.UICommon.instantiate(Unknown Source)
         at oracle.forms.handler.UICommon.onCreate(Unknown Source)
         at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
         at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
         at oracle.forms.engine.Runform.processMessage(Unknown Source)
         at oracle.forms.engine.Runform.processSet(Unknown Source)
         at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
         at oracle.forms.engine.Runform.onMessage(Unknown Source)
         at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$200(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    network: Connecting http://192.168.10.100:7778/forms/lservlet;jsessionid=c0a80a6430d6e191eded93774f2f8d1bed73056e66ef.e3mObhiMbxeKe34PahiKbx4Nbh90n6jAmljGr5XDqQLvpAe with proxy=DIRECT
    Exception in thread "Forms-DialogThread2" java.lang.NullPointerException
         at oracle.forms.handler.JavaContainer.onDestroy(Unknown Source)
         at oracle.forms.engine.Runform.destroyHandlers(Unknown Source)
         at oracle.forms.handler.DialogThread.doAlert(Unknown Source)
         at oracle.forms.handler.DialogThread.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Dumping class loader cache...
    Live entry: key=http://192.168.10.100:7778/forms/java/,frmall.jar,siberia_jpg.jar,ApiConn.jar,ConcealTextField.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://192.168.10.100:7778/forms/java/-threadGroup,maxpri=4]
    Done.
    here is my java file
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package oracle.forms.siberia;
    * This contains connection. Everything should be here,
    * should operate with this class only
    import java.io.*;
    import java.net.*;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import oracle.forms.*;
    * @author janisk
    public class ApiConn extends Thread {
    private Socket sock = null;
    private DataOutputStream out = null;
    private DataInputStream in = null;
    private String ipAddress;
    private int ipPort;
    private boolean connected = false;
    private String message = "Not connected";
    private ReadCommand readCommand = null;
    private WriteCommand writeCommand = null;
    private Thread listener = null;
    LinkedBlockingQueue queue = new LinkedBlockingQueue(40);
    * Constructor of the connection class
    * @param ipAddress - IP address of the router you want to conenct to
    * @param ipPort - port used for connection, ROS default is 8728
    public ApiConn(String ipAddress, int ipPort) {
    this.ipAddress = ipAddress;
    this.ipPort = ipPort;
    this.setName("settings");
    * State of connection
    * @return - if connection is established to router it returns true.
    public boolean isConnected() {
    return connected;
    public void disconnect() throws IOException{
    listener.interrupt();
    sock.close();
    private void listen() {
    if (this.isConnected()) {
    if (readCommand == null) {
    readCommand = new ReadCommand(in, queue);
    listener = new Thread(readCommand);
    listener.setDaemon(true);
    listener.setName("listener");
    listener.start();
    * to get IP address of the connection. Reads data from socket created.
    * @return InetAddress
    public InetAddress getIpAddress() {
    return sock == null ? null : sock.getInetAddress();
    * returns ip address that socket is asociated with.
    * @return InetAddress
    public InetAddress getLocalIpAddress() {
    return sock == null ? null : sock.getLocalAddress();
    * Socket remote port number
    * @return
    public int getPort() {
    return sock == null ? null : sock.getPort();
    * return local prot used by socket
    * @return
    public int getLocalPort() {
    return sock == null ? null : sock.getLocalPort();
    * Returns status message set up bu class.
    * @return
    public String getMessage() {
    return message;
    * sets and exectues command (sends it to RouterOS host connected)
    * @param s - command will be sent to RouterOS for example "/ip/address/print\n=follow="
    * @return
    public String sendCommand(String s) {
    return writeCommand.setCommand(s).runCommand();
    * exeecutes already set command.
    * @return returns status of the command sent
    public String runCommand() {
    return writeCommand.runCommand();
    * Tries to fech data that is repllied to commands sent. It will wait till it can return something.
    * @return returns data sent by RouterOS
    * @throws java.lang.InterruptedException
    public String getData() throws InterruptedException {
    String s = (String) queue.take();
    return s;
    * returns command that is set at this moment. And will be exectued if runCommand is exectued.
    * @return
    public String getCommand() {
    return writeCommand.getCommand();
    * set up method that will log you in
    * @param name - username of the user on the router
    * @param password - password for the user
    * @return
    public String login(String name, char[] password) {
    this.sendCommand("/login");
    String s = "a";
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #1";
    if (!s.contains("!trap") && s.length() > 4) {
    String[] tmp = s.trim().split("\n");
    if (tmp.length > 1) {
    tmp = tmp[1].split("=ret=");
    s = "";
    String transition = tmp[tmp.length - 1];
    String chal = "";
    chal = Hasher.hexStrToStr("00") + new String(password) + Hasher.hexStrToStr(transition);
    chal = Hasher.hashMD5(chal);
    String m = "/login\n=name=" + name + "\n=response=00" + chal;
    s = this.sendCommand(m);
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #2";
    if (s.contains("!done")) {
    if (!s.contains("!trap")) {
    return "Login successful";
    return "Login failed";
    @Override
    public void run() {
    try {
    InetAddress ia = InetAddress.getByName(ipAddress);
    if (ia.isReachable(1000)) {
    sock = new Socket(ipAddress, ipPort);
    in = new DataInputStream(sock.getInputStream());
    out = new DataOutputStream(sock.getOutputStream());
    connected = true;
    readCommand = new ReadCommand(in, queue);
    writeCommand = new WriteCommand(out);
    this.listen();
    message = "Connected";
    } else {
    message = "Not reachable";
    } catch (UnknownHostException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    } catch (IOException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    }

  • UnsatisfiedLinkError,   Load Library Successfully, Native Method Not Found

    I am using JNI to call a ".dll" file I made on windows.
    I got the exception:
    Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: com.aspectgaming.core.io.JniInnocore.Dpci.waitEvent(Ljava/lang/Object;J)I
    at com.aspectgaming.core.io.JniInnocore.Dpci.waitEvent(Native Method)
    at com.aspectgaming.core.io.JniInnocore.IDLPThread.run(IDLPThread.java:19)
    at java.lang.Thread.run(Unknown Source)
    The code for loading c dll library:
    URL url = Thread.currentThread().getContextClassLoader().getResource("");
    String baseClassPath = url.getPath();
    System.load(baseClassPath "com/aspectgaming/libjnidpcicore.dll");+
    The  ".dll"  file is already loaded,  because when I changed the dll file name to any other ones,  a "library file not found" exception will be caught.
    The problem is Dpci.waitEvent and all the native methods could not be found.
    I used a PE viewer to view the dll exports I got:
    Export table
    Characteristics=0, TimeDateStamp=1237366066, MajorVersion=0, MinorVersion=0, Name=36994, Base=1, NumberOfFunctions=9, NumberOfNames=9, AddressOfFunctions=36904, AddressOfNames=36940, AddressOfNameOrdinals=36976,
    TimeDateStamp:Wed Mar 18 16:47:46 GMT+08:00 2009
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_getEventName@12 (Ordinal: 1, Entry Point RVA: 147ah (5,242))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_getNumOfEvents@8 (Ordinal: 2, Entry Point RVA: 11a5h (4,517))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_getNumOfInputPorts@12 (Ordinal: 3, Entry Point RVA: 1789h (6,025))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_getSramSize@8 (Ordinal: 4, Entry Point RVA: 1190h (4,496))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_readEvent@12 (Ordinal: 5, Entry Point RVA: 11bah (4,538))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_readPort@12 (Ordinal: 6, Entry Point RVA: 17a7h (6,055))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_waitEvent@20 (Ordinal: 7, Entry Point RVA: 14b8h (5,304))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_waitIOPort@24 (Ordinal: 8, Entry Point RVA: 17dbh (6,107))
    Java_com_aspectgaming_core_io_JniInnocore_Dpci_writePort@16 (Ordinal: 9, Entry Point RVA: 182ch (6,188))
    The java class "Dpci" is exactly in this package : com.aspectgaming.core.io.JniInnocore;
    I compiled it by gcc on linux as a ".so" file and everything is working on linux.
    On windows I am compiling this by Mingw gcc.
    Here is the make file on Windows which is used by Mingw32-make:
    dpci_core:
    gcc -o ../../../java/com/aspectgaming/libjnidpcicore.dll -shared -IC:\jdk1.6.0_10\include -IC:\jdk1.6.0_10\include\win32 -I'D:\Program Files\Innocore Gaming Ltd\DirectPCI SDK & Run-time\include' dpci_core.c libdpci_static.lib
    dpci_core.c is my code file and  libdpci_static.lib is the library that my c dll will depend on.
    Any thought to this UnsatisfiedLinkError exception problem?
    Thanks!

    I recompile my codes under visual c++ 2008 express on Windows XP professional, and I have already got rid of this problem.
    But when I move the compiled java jar application to windows xp embedded edition, an exception will be caught:
    C:\AspectGamingCore>java -jar Aspect.jar
    Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\AspectGamingCore\l
    ib\libjnidpcicore.dll: This application has failed to start because the applicat
    ion configuration is incorrect. Reinstalling the application may fix this proble
    m
    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.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.aspectgaming.core.io.JniInnocore.Dpci.loadLibraryOnWindows(Unknow
    n Source)
    at com.aspectgaming.core.io.JniInnocore.DpciTest.main(Unknown Source)
    I don't know if there is any compatible problem bewteen xp and xpe but one possible reason is that xpe may be lack of some dll files like msvcr90.dll.
    So I tried to compile the dll as static library in vc++2008, but this does not run even on my winxp professional:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\AspectGamingCore\l
    ib\libjnidpcicore.dll: %1 is not a valid Win32 application
    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.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.aspectgaming.core.io.JniInnocore.Dpci.loadLibraryOnWindows(Unknow
    n Source)
    at com.aspectgaming.core.io.JniInnocore.DpciTest.main(Unknown Source)
    Could JNI call a c static library? Why it says "not a valid Win32 application"?

Maybe you are looking for