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 '-').
Similar Messages
-
Problem: Native method only works one
Hi, I have this class that calls the GetShortName method from the windows API.I have created the asociated DLL and everything went quite smooth.
My problem is that when I make a new object of the class GetShortNameA and use the method TranslateIntoShort(String) this only works the fist time.
The rest of the times I try to use this method with other arguments I am getting the same answer that I was getting the first time I call it.
Why can this be and how can I fix it??
I have tried declaring the TranslateIntoShort method non-static, but then the whole thing doesn't work (evena fter regenerating the h file and the DLL).
package alfagui_1;
public class GetShortNameA {
public GetShortNameA() {
static{
System.loadLibrary("GetShortPathNameA");
public static native String TranslateIntoShort(String LongName);
GetShortNameA ShortName = new GetChortNameA();
First time:
ShortName.TranslateIntoShort("C:\Mina Dokument\alfa")-->"C:\Minado~1\alfa"
Sucessive calls:
ShortName.TranslateIntoShort(WHATEVER)-->"C:\Minado~1\alfa"
Thanks for your helpPerhaps if you posted your code we could point out the problem?
-
Problems with c++ native methods
hello to all ,
I am building an client-server application in java , which uses java native methods written
in c++ .In every client's request , the applcation updates a hashtable .The hashtable is kept as an
Object member variable in a java class .So updating the hashtable is like this : the native method is
called which accesses the Object member variable , updates the hashtable and sets the new Object
member variable value.
That's the way that it should work ,but i am experiencing some serious problems because the jvm
keeps on crashing with UNEXCPECTED SIGNAL 11 .My distribution is Mandrake 9.0 ,and i use java
j2sdk1.4.1_01
Here some very naive questions i have to ask :
1.Is it possible that the jvm crashes because the size of the hashtable is not fixed ?
2.Can it be a system problem (like libgcc ) or else ?
Any opinion on this would be very helpful
Thanks in advance ,
Sbile
P.S. Here the log file being created after every crash
Unexpected Signal : 11 occurred at PC=0x404657B6
Function=is_forwarded__C7oopDesc+0x6
Library=/usr/local/j2sdk1.4.1_01/jre/lib/i386/client/libjvm.so
Dynamic libraries:
08048000-0804e000 r-xp 00000000 03:06 463913 /usr/local/j2sdk1.4.1_01/bin/java
0804e000-0804f000 rw-p 00005000 03:06 463913 /usr/local/j2sdk1.4.1_01/bin/java
40000000-40011000 r-xp 00000000 03:06 278533 /lib/ld-2.2.5.so
40011000-40012000 rw-p 00010000 03:06 278533 /lib/ld-2.2.5.so
40013000-4001c000 r-xp 00000000 03:06 119905 /usr/local/j2sdk1.4.1_01/jre/lib/i386/native_threads/libhpi.so
4001c000-4001d000 rw-p 00008000 03:06 119905 /usr/local/j2sdk1.4.1_01/jre/lib/i386/native_threads/libhpi.so
4001e000-40021000 r--s 00000000 03:06 447528 /usr/local/j2sdk1.4.1_01/jre/lib/ext/dnsns.jar
40021000-40022000 r--s 00000000 03:06 198504 /usr/lib/kaffe/lib/microsoft.jar
40022000-4002f000 r-xp 00000000 03:06 573447 /lib/i686/libpthread-0.9.so
4002f000-40036000 rw-p 0000d000 03:06 573447 /lib/i686/libpthread-0.9.so
40036000-40038000 r-xp 00000000 03:06 278544 /lib/libdl-2.2.5.so
40038000-40039000 rw-p 00001000 03:06 278544 /lib/libdl-2.2.5.so
40039000-40150000 r-xp 00000000 03:06 573443 /lib/i686/libc-2.2.5.so
40150000-40155000 rw-p 00117000 03:06 573443 /lib/i686/libc-2.2.5.so
40159000-40471000 r-xp 00000000 03:06 119911 /usr/local/j2sdk1.4.1_01/jre/lib/i386/client/libjvm.so
40471000-40625000 rw-p 00317000 03:06 119911 /usr/local/j2sdk1.4.1_01/jre/lib/i386/client/libjvm.so
40635000-40646000 r-xp 00000000 03:06 278548 /lib/libnsl-2.2.5.so
40646000-40647000 rw-p 00011000 03:06 278548 /lib/libnsl-2.2.5.so
40649000-4066b000 r-xp 00000000 03:06 573445 /lib/i686/libm-2.2.5.so
4066b000-4066c000 rw-p 00021000 03:06 573445 /lib/i686/libm-2.2.5.so
4066c000-4067c000 r-xp 00000000 03:06 119915 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libverify.so
4067c000-4067e000 rw-p 0000f000 03:06 119915 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libverify.so
4067e000-4069f000 r-xp 00000000 03:06 119916 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libjava.so
4069f000-406a1000 rw-p 00020000 03:06 119916 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libjava.so
406a1000-406b6000 r-xp 00000000 03:06 119918 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libzip.so
406b6000-406b8000 rw-p 00014000 03:06 119918 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libzip.so
406b8000-41d86000 r--s 00000000 03:06 119961 /usr/local/j2sdk1.4.1_01/jre/lib/rt.jar
41dc9000-41de0000 r--s 00000000 03:06 119941 /usr/local/j2sdk1.4.1_01/jre/lib/sunrsasign.jar
41de0000-41e51000 r--s 00000000 03:06 119943 /usr/local/j2sdk1.4.1_01/jre/lib/jsse.jar
41e51000-41e64000 r--s 00000000 03:06 119942 /usr/local/j2sdk1.4.1_01/jre/lib/jce.jar
41e64000-42120000 r--s 00000000 03:06 119959 /usr/local/j2sdk1.4.1_01/jre/lib/charsets.jar
441c8000-441ca000 r--s 00000000 03:06 198471 /usr/lib/kaffe/lib/comm.jar
441ca000-441cc000 r--s 00000000 03:06 198505 /usr/lib/kaffe/lib/pjava.jar
441cc000-441d0000 r--s 00000000 03:06 185441 /usr/local/j2sdk1.4.1_01/lib/servlet.jar
4c3d3000-4c3fe000 r--p 00000000 03:06 212998 /usr/share/locale/ISO-8859-15/LC_CTYPE
4c3fe000-4c40c000 r--s 00000000 03:06 447534 /usr/local/j2sdk1.4.1_01/jre/lib/ext/ldapsec.jar
4c40d000-4c416000 r-xp 00000000 03:06 278554 /lib/libnss_files-2.2.5.so
4c416000-4c417000 rw-p 00008000 03:06 278554 /lib/libnss_files-2.2.5.so
4c61b000-4c638000 r--s 00000000 03:06 447527 /usr/local/j2sdk1.4.1_01/jre/lib/ext/sunjce_provider.jar
4c638000-4c6d7000 r--s 00000000 03:06 447529 /usr/local/j2sdk1.4.1_01/jre/lib/ext/localedata.jar
4c6d7000-4c6eb000 r--s 00000000 03:06 198506 /usr/lib/kaffe/lib/rmi.jar
4c6eb000-4cb9e000 r--s 00000000 03:06 185437 /usr/local/j2sdk1.4.1_01/lib/tools.jar
4cb9e000-4cc93000 r--s 00000000 03:06 198503 /usr/lib/kaffe/lib/kjc.jar
4cc93000-4cd9e000 r--s 00000000 03:06 198507 /usr/lib/kaffe/lib/rt.jar
4cd9e000-4cda6000 r--s 00000000 03:06 201714 /usr/lib/kaffe/lib/sax.jar
4cda6000-4cf61000 r--s 00000000 03:06 201715 /usr/lib/kaffe/lib/xerces.jar
4cf61000-4cf81000 r--s 00000000 03:06 201713 /usr/lib/kaffe/lib/jdom.jar
4cf81000-4cf85000 r-xp 00000000 03:06 266660 /home/sbile/diplomatikh/build/src/lib/libBuildHashTable.so
4cf85000-4cf86000 rw-p 00004000 03:06 266660 /home/sbile/diplomatikh/build/src/lib/libBuildHashTable.so
4cf95000-4d03e000 r-xp 00000000 03:06 508019 /usr/lib/libstdc++.so.5.0.0
4d03e000-4d054000 rw-p 000a8000 03:06 508019 /usr/lib/libstdc++.so.5.0.0
4d059000-4d060000 r-xp 00000000 03:06 278604 /lib/libgcc_s-3.2.so.1
4d060000-4d061000 rw-p 00007000 03:06 278604 /lib/libgcc_s-3.2.so.1
4d0e2000-4d0f2000 r-xp 00000000 03:06 119921 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libnet.so
4d0f2000-4d0f4000 rw-p 0000f000 03:06 119921 /usr/local/j2sdk1.4.1_01/jre/lib/i386/libnet.so
Local Time = Sat May 10 04:25:40 2003
Elapsed Time = 7
# HotSpot Virtual Machine Error : 11
# Error ID : 4F530E43505002E6
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
# Java VM: Java HotSpot(TM) Client VM (1.4.1_01-b01 mixed mode)
# An error report file has been saved as hs_err_pid4063.log.
# Please refer to the file for further information.The dreaded Signal 11 means you've overwritten some memory you're not supposed to.
Check that all of your array indexes are in range, that you're not accessing memory that's been freed etc etc.
Try placing print statements at strategic places in your native code to narrow down the problem -
Problem in running a web service having Native Method invocation
Hi guys,
i am trying a run web service, that is calling some Native Method
The arguement for the operation is a byte[] and the return type is boolean.
The web service type i am using is "Documentary-Literal"
Actually what happend is, whenever i am calling the web service, i didn't get any error or exception, but i didn't get any output too.
if the code inside the operation is executed properly then, operation should return FALSE, but now it is returning TRUE.
What may be the problem?
someone help me..........
thanx,
subbuHi guys,
i am trying a run web service, that is calling some Native Method
The arguement for the operation is a byte[] and the return type is boolean.
The web service type i am using is "Documentary-Literal"
Actually what happend is, whenever i am calling the web service, i didn't get any error or exception, but i didn't get any output too.
if the code inside the operation is executed properly then, operation should return FALSE, but now it is returning TRUE.
What may be the problem?
someone help me..........
thanx,
subbu -
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.0Did 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". -
Hi again friends,
I'm using JDEV to develop OAF, I have no problem doing unit test with Mockito, and Junit 3.x. JUnit 3 is the officially supported version for my IDE build.
I wanted to use JUnit 4, so I decided to just run my tests using ant build file. Everything compiled fine after adding the jar/zip files from jdev one after another in the ant classpath.
But when I try to run the unit test, I am getting this NoClassDefFoundError apparently from a class file is I already included in the build file. The method call having problem same version jar file Mockito.
[junit] java.lang.NoClassDefFoundError: oracle/adf/mds/repos/DatabaseContext
[junit] at java.lang.Class.getDeclaredConstructors0(Native Method)
[junit] at java.lang.Class.privateGetDeclaredConstructors(Class.java:238
[junit] at java.lang.Class.getDeclaredConstructors(Class.java:1836)
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.setCons
ructorsAccessible(ClassImposterizer.java:58)
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.imposte
ise(ClassImposterizer.java:53)
[junit] at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:5
[junit] at org.mockito.internal.MockitoCore.mock(MockitoCore.java:45)
[junit] at org.mockito.Mockito.mock(Mockito.java:921)
[junit] at org.mockito.Mockito.mock(Mockito.java:816)Please share some ideas, thanls.
I'll try to see what happens If I use JUnit3.0 in with ant... Same error.
Maybe while the Class in question is being instantiated, it silently depend on another class that is not present in my classpath...That's exactly the case, solved by including all jar files defined for the project in jdev.
Sorry for the monologue.
Edited by: thedatawarehouse on Apr 25, 2011 4:34 PMI'm unfamiliar with JDEV, but the short answer is: Find where oracle.adf.mds.repos.DatabaseContext.class is on your machine & add it to your classpath.
-
Accessing a native method from within a packaged class
I have seen some very useful information from RPaul. However, I can not quite get it to work.
I have a class "JNIGetUserId" that is in a package "com.services.localoptions". I am trying to call a native method from a dll. it works fine at the default package level. But not in the package. I have tried adding the "_" between each level of the directory in the h and c++ files. I also found that doing a javah at the top of the package structure it includes some information in the h file. A "_0005" shows up between each level.
This is on Windows XP. I am also using VisualAge for Java. I also am using JDK 1.3.1.
The source files:
package com.services.localoptions;
* This class provides the JNI Interface to call the
* AD User Maintainence routines.
* These routines are stored in the JNIGetUserIdLibrary.dll.
* The routines are:
* <ul>
* <li>getUser - returns a string containing the User Id
* <eul>
* @author: Ray Rowehl
* @date (10/15/2003 10:30:59 AM)
public class JNIGetUserId
// Load the library
static
try
System.out.println("loading dll");
System.loadLibrary("JNIGetUserIdLibrary");
System.out.println("loaded dll");
catch (UnsatisfiedLinkError ue)
System.out.println("Link Error");
* native C++ method to call getUserId routine
public native String getUser() throws Exception;
* This method allows us to test standalone..
* Creation date: (10/16/2003 2:08:58 PM)
* @param args java.lang.String[]
public static void main(String[] args)
try
System.out.println("Trying method 3");
JNIGetUserId lGUD = new JNIGetUserId();
System.out.println(lGUD.getUser());
catch (Exception e)
System.out.println("Got an exception " + e);
e.printStackTrace();
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNIGetUserId */
#ifndef IncludedJNIGetUserId
#define IncludedJNIGetUserId
#ifdef __cplusplus
extern "C" {
#endif
* Class: JNIGetUserId
* Method: getUser
* Signature: ()Ljava/lang/String;
JNIEXPORT jstring JNICALL Java_com_localoptions_JNIGetUserId_getUser
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endif
// Implements method to return a string to Java
// C++ core header
#include <iostream.h>
// header from Java Interface
#include "JNIGetUserId.h"
#include "JNIGetUserId2.h"
// returns a string back to Java for package structure
JNIEXPORT jstring JNICALL Java_com_services_localoptions_JNIGetUserId_getUser
( JNIEnv * env, jobject thisObject )
// set up constant user id for testing return
char* userid = "RROWEHLP";
// return userid to caller
return env->NewStringUTF( userid );
// returns a string back to Java for flat structure
JNIEXPORT jstring JNICALL Java_JNIGetUserId_getUser
( JNIEnv * env1, jobject thisObject1 )
// set up constant user id for testing return
char* userid1 = "RROWEHL1";
// return userid to caller
return env1->NewStringUTF( userid1 );
}Ok. A co-worker figured it out for me. The key thing is to do "javah com.services.localoptions.JNIGetUserId". Note the use of "." instead of "\". Running on windows, I was used to doing "\". That was part of the problem. Another key is doing the javah at the top of the package structure. This was mentioned in a post over at IBM.
We got our JNI stuff working now. thanks, ray. -
What's wrong about native method?
when I call c navtive method under the Solorais 8 and JDK 1.4.2.
what's wrong?why??
Unexpected Signal : 11 occurred at PC=0xFE0EEA28
Function=[Unknown. Nearest: JVM_IsSupportedJNIVersion+0x988]
Library=/usr/j2sdk1.4.2/jre/lib/sparc/client/libjvm.so
Current Java thread:
at jp.co.dir.am.faimsam.G02F_NativeJniPrt.JNI_BG_trsMrktName(Native Method)
at jp.co.dir.am.faimsam.print.core.creater.G02IF007.exeSimple(G02IF007.java:70)
at jp.co.dir.am.faimsam.print.core.controller.PrintGenerator.process(Unknown Source)
at jp.co.dir.am.faimsam.print.core.controller.Handler.handlePrint(Unknown Source)
at jp.co.dir.am.faimsam.print.web.WebWorker.run(Unknown Source)
at java.lang.Thread.run(Thread.java:534)
Dynamic libraries:
0x10000 java
0xff350000 /usr/lib/libthread.so.1
0xff390000 /usr/lib/libdl.so.1
0xff200000 /usr/lib/libc.so.1
0xff330000 /usr/platform/SUNW,Ultra-4/lib/libc_psr.so.1
0xfe000000 /usr/j2sdk1.4.2/jre/lib/sparc/client/libjvm.so
0xff2e0000 /usr/lib/libCrun.so.1
0xff1e0000 /usr/lib/libsocket.so.1
0xff100000 /usr/lib/libnsl.so.1
0xff0d0000 /usr/lib/libm.so.1
0xff1c0000 /usr/lib/libsched.so.1
0xff310000 /usr/lib/libw.so.1
0xff0a0000 /usr/lib/libmp.so.2
0xff040000 /usr/j2sdk1.4.2/jre/lib/sparc/native_threads/libhpi.so
0xfe7d0000 /usr/j2sdk1.4.2/jre/lib/sparc/libverify.so
0xfe790000 /usr/j2sdk1.4.2/jre/lib/sparc/libjava.so
0xfe760000 /usr/j2sdk1.4.2/jre/lib/sparc/libzip.so
0xfe490000 /usr/lib/locale/ja/ja.so.2
0xfe590000 /usr/lib/locale/ja/methods_ja.so.2
0xfddb0000 /usr/j2sdk1.4.2/jre/lib/sparc/libnet.so
0xfdd90000 /usr/j2sdk1.4.2/jre/lib/sparc/libnio.so
0xfc3d0000 /usr/lib/librt.so.1
0xfc3b0000 /usr/lib/libaio.so.1
0xfc390000 /usr/lib/libsendfile.so.1
0xfc2c0000 /home1/fam/apl/print/lib/libG02JB.so
Heap at VM Abort:
Heap
def new generation total 2112K, used 244K [0xf1400000, 0xf1620000, 0xf1b10000)
eden space 2048K, 8% used [0xf1400000, 0xf142d138, 0xf1600000)
from space 64K, 100% used [0xf1610000, 0xf1620000, 0xf1620000)
to space 64K, 0% used [0xf1600000, 0xf1600000, 0xf1610000)
tenured generation total 1408K, used 326K [0xf1b10000, 0xf1c70000, 0xf5400000)
the space 1408K, 23% used [0xf1b10000, 0xf1b61a00, 0xf1b61a00, 0xf1c70000)
compacting perm gen total 4096K, used 2740K [0xf5400000, 0xf5800000, 0xf9400000)
the space 4096K, 66% used [0xf5400000, 0xf56ad168, 0xf56ad200, 0xf5800000)
Local Time = Tue Sep 9 15:25:56 2003
Elapsed Time = 14
# HotSpot Virtual Machine Error : 11
# Error ID : 4F530E43505002EF 01
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
# Java VM: Java HotSpot(TM) Client VM (1.4.2-b28 mixed mode)
# An error report file has been saved as hs_err_pid19029.log.
# Please refer to the file for further information.I dont know if it actually helps, but following the link
http://www.cs.pub.ro/~gaburici/nstomcat/diss.html#solpre
there are some problems mentioned that still seem to be in Java for Linux/Unix.
Try to set
LD_PRELOAD=/usr/j2sdk1.4.2/jre/lib/sparc/client/libjvm.so
before you start the program.
(I assume you loaded the library via dlopen)
Hope it works... -
How to put native methods in jar file
Hi.I have an executable jar file(test.jar) that makes use of other jar files and native methods. For example, test.jar uses Jnpout32.dll. . test.jar , the other jar files and the native methods are all in the same directory. When I created test.jar I wrote a manifest file which specifies the class path of the other jar files and the native methods as follows and provided it as an option in the jar cfmev command.
Class Path: jdbc.jar Jnpout32reg.dll //content of manifest.txt file that I provided to the jar command
//carriage return I then run the command java -jar test.jar to run the file.
All I am seeing is the following error message
Exception in thread "AWT EventQueue-o
"Java.lang.NoClassDefFoundError.
gnu/io/SerialPortEventListner"
{code}
Any ideas? thanks in advance!
Edited by: Nostalgia on May 22, 2009 8:05 AMYou seem to be confusing Java's classpath with your os's path. The classpath only applies to Java classes. See if this discussion helps:
http://www.inonit.com/cygwin/jni/helloWorld/load.html -
How do I declare a native method outside of the main class?
Hi
This is a JNI particular question.
I am having a problem with generating the header .h file after executing javah. The file is generated correctly but is empty under certain circumstances.
This is the 'empty file:
=================
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class gui_GuiMain */
#ifndef Includedgui_GuiMain
#define Includedgui_GuiMain
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
#endif
#endif
This is what it should look like:
=========================
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class gui_GuiMain */
#ifndef Includedgui_GuiMain
#define Includedgui_GuiMain
#ifdef __cplusplus
extern "C" {
#endif
* Class: gui_GuiMain
* Method: getValueOIDTestMIB
* Signature: ()V
JNIEXPORT void JNICALL Java_gui_GuiMain_getValueOIDTestMIB
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endif
The header file becomes "empty" when the native function getValueOIDTestMIB is declared in a different class than what my main() function is declared in.
For example something like this will work:
class Main
public native void getValueOIDTestMIB
static {
System.loadLibrary("libsnmp++");
//............some more functions etc.............
public static void main(String[] args)
//............some more stuff...........................
But when I declare this:
public native void getValueOIDTestMIB
static {
System.loadLibrary("libsnmp++");
outside the class, in another class within the same package, nothing happens.
I am probabily doing something stupid. Can somebody help or give me some guidance to where I should look. I come from a C++ background, not a guru in Java.
ThanksYou need to run javah and give it as a parameter the full class name of the class which contains the native methods.
For example (if your class is called A and its package is a.b.c)
javah -jni a.b.c.A -
JNI Calls to Native Methods No Longer Work: Possible Versioning Issue ?
Hello, all. Just a quick question... is it possible that invoking a method in a JNI-compliant DLL from Java 6 will fail if the DLL's source was compiled against the JNI header files from Java 4 or 5 ? I have a DLL with methods that used to be called successfully (and now fail outright and don't even seem to be getting inside the native method), but it seems that the only thing that could have changed in the environment is the installed JRE. Even stranger, I don't get the hs_err* files anymore to indicate that the JVM crashed. Does anyone know why this might happen ? Thanks !
Cthulhu76 wrote:
Hello, all. Just a quick question... is it possible that invoking a method in a JNI-compliant DLL from Java 6 will fail if the DLL's source was compiled against the JNI header files from Java 4 or 5 ? Solely? No.
You could of course be doing something in the JNI code in terms of working with Java which no longer works. Just as it is at least possible that java code from one version might not work with another.
Correct error checking in the JNI code would at least correctly identify this problem however.
I have a DLL with methods that used to be called successfully (and now fail outright and don't even seem to be getting inside the native method), but it seems that the only thing that could have changed in the environment is the installed JRE.The only thing that you assume changed was the JRE.
You seem unsure whether the JNI is being called at all, so verifying that first would be a good idea. -
A way to set a flag in java layer when native method has been called?
Hi,
I'm calling a native method from the java layer through to a native c function. Is there a way I can set a flag in the java layer when this native method has been called?
Thanks!1. Create a wrapper method. The wrapper method is the only exposed method. It calls the native method. It sets the flag.
2. Set the flag in the native method itself.
3. You might be able to use the debugging API to do this however it is going to require quite a bit of work. And it injects itself at runtime.
Is there a reason for this request? There might be other solutions if a general problem was posed. -
Calling multiple DLL from Java and calling same native method
i have two dll files named DLL_1.dll and DLL_2.dll .
Both of them contain a native method which has a signature
JNIEXPORT void JNICALL Java_Database_Notify
(JNIEnv *, jclass);
This method is common to both the DLL
Now i load both of the DLL's using,
System.loadLibrary("DLL_1");
System.loadLibrary("DLL_2");
Both of the DLL are loaded form same Java Application
But the problem is that , whenever i try to call the Notify Method , it calls the Notify method of DLL_1 only.
How do i call the Notify Methos of second DLL(i.e DLL_2).
Is there any reference that i can get to all the DLL files when i load then , so that i can use that reference to invoke the Notify method of that particular DLL.i have two dll files named DLL_1.dll and DLL_2.dll .
Both of them contain a native method which has a
signature
JNIEXPORT void JNICALL Java_Database_Notify
(JNIEnv *, jclass);
This method is common to both the DLL
Now i load both of the DLL's using,
System.loadLibrary("DLL_1");
System.loadLibrary("DLL_2");
Both of the DLL are loaded form same Java
Application
But the problem is that , whenever i try to call the
Notify Method , it calls the Notify method of DLL_1
only.
How do i call the Notify Methos of second DLL(i.e
DLL_2).
Is there any reference that i can get to all the DLL
files when i load then , so that i can use that
reference to invoke the Notify method of that
particular DLL.You need to explain exactly what you are trying to achieve.
As per the description above it is impossible in java.
And I didn't say JNI, I said java.
Your above statement suggests that you think that you can have exactly the same java signature do two different things.
Note again that I said java not JNI.
A JNI method is just a tag that represents a java signature. Your description suggests that you are attempting to do it twice.
There are three possibilities.
1. Your explanation is incomplete.
2. You are trying to do something that is impossible in java.
3. You are trying to solve a problem and your description of your solution is not sufficient to determine what that is (and of course the solution is wrong.) -
Call native methods from windows dll
Hello all,
I want to call BlockInput method from User32.dll. My source code looks something like this:
public class User32Dll_1 {
static {
try {
System.loadLibrary("User32");
catch (Exception ex)
ex.printStackTrace();
public static void main(String[] args) throws UnsatisfiedLinkError {
BlockInput (true);
/** @param b
* @dll.import("USER32")*/
private static native boolean BlockInput(boolean bBOOL);
And the problem is that I get the following exception:
java.lang.UnsatisfiedLinkError: BlockInput
at User32Dll_1.BlockInput(Native Method)
at User32Dll_1.main(User32Dll_1.java:27)
Exception in thread "main"
Can someone provide me a solution for this?
Thank you in advance!can't do
use JACOB
http://danadler.com/jacob/
or
http://www.ezjcom.com/ -
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
-
How can I delete old Apple Software Updates from 10.6 server?
Hi guys!! First of all, please, excuse my english......i know it's the worst possible and will try to develop it. My question is the following. The hard disk of my xServe is almost full and I need to delete the old Apple Software Udates that it conta
-
Price comparision in ECC 6.0
Hi, we are moving from 4.6 c to ecc 6.0.I am facing problem while comparing quotations.In 4.6 c,it is working fine but in ecc 6.0 giving an error. I put the collective RFQ number in the initial screen while carrying out T-code ME49. when i execute in
-
I downloaded Firefox 4 on my pc laptop and I loved it so much I wanted to put it on my mac, but I didn't realize it would not work until I had already downloaded it and replaced the firefox I had. I want to get back to any kind of firefox because I p
-
Is there a replacement for the canon 7d
Is there a replacement for the canon 7d
-
Copies disabled when printing directly to Printer
Using release Release 10.1.3.2.0, server. Why is BIP always defaulting to 1 copy when printing to a direct printer. It seems to completely ignore the number of copies parameter. I am doing a http post to the scheduler by the way, since we would like