When you created the header file you surely used "javah -jni yourClass", right?
If not don't keep on reading and tell me exactely what you did.
 
Okay, this problem always comes up when the Class impelemting your native code is part of a package. The tutorials on the internet only deal with a single class, like
a hello world programm for instance.
 
When you take a look in your header file, the class and the functions should be defined like this:
 
JAVAEXPORT jint (or jvoid or what else) JNICALL Java_yourClass_yourMethod(jENV *, ,jobject)
 
But your class is not defined as yourClass - it should be yourPackage.yourClass.
 
So move up one directory above your package and use javah -jni yourPackage/yourClass. A header file will be created with the name yourPackage_0002fyourClass.h
Change the name to anything you feel comfortale with. Then open the header file. Your functions will be defined like this:
 
JAVAEXPORT jint (or jvoid or what else) JNICALL Java_yourPackage_0002fyourClass_yourMethod(jENV *, ,jobject)
 
I'm not sure if you will find "_0002f". This could be different from one system to the other. I think it is a representation of how your operating system manages directories.
But who cares? Just delete everything in the header file that should not be there in order to make it look like this:
 
JAVAEXPORT jint (or jvoid or what else) JNICALL Java_yourPackage_yourClass_yourMethod(jENV *, ,jobject)
 
Now write your native code and take care to define the functions exactely the way you see them in the header file.
 
Another problem you will find, when this works:
 
When I did it all this way, everything seemed to work fine. But using a package the JVM won't find the shared library while executing your application. I don't no why, but I've found a way to ship around. In your class implementing the native code don't write:
 
System.loadLibrary("yourLibrary");
 
use instead:
 
System.load("/yourDirectories.../.../libyourLibrary.so");
 
This will work. If you still have problems keep on asking, but please write exactely what you did and explain the structure of your packages and directories.
 
Bye
 
-----Ursprüngliche Nachricht-----
Von: Harald Pollak [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 16. Juli 2003 09:19
An: [EMAIL PROTECTED]
Betreff: Re: JNI problem

please let me know if you have a solution, I have a simmular problem, but I have no solution until jet.

nice day
Harry

On Die, 2003-07-15 at 05:16, SEong CHEE wrote:
Hi everyone,

I tried to use JNI within a Axis service.
I had compile the java code to .class file, then created the .h file, also 
written thet native method implementation in .c file, finally created the 
shared library.
The program can be run successfully, but when I tried to deploy it, I always 
get the following error message: (may I know all this files should put under 
which folder)

500 Servlet Exception
java.lang.NoClassDefFoundError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:217)
	at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:187)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:171)
	at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:154)
	at org.apache.axis.utils.cache.ClassCache.lookup(ClassCache.java:122)
	at 
org.apache.axis.providers.java.JavaProvider.getServiceClass(JavaProvider.java:502)
	at 
org.apache.axis.providers.java.JavaProvider.initServiceDesc(JavaProvider.java:535)
	at 
org.apache.axis.handlers.soap.SOAPService.getInitializedServiceDesc(SOAPService.java:322)
	at 
org.apache.axis.deployment.wsdd.WSDDService.makeNewInstance(WSDDService.java:477)
	at 
org.apache.axis.deployment.wsdd.WSDDDeployment.getDeployedServices(WSDDDeployment.java:566)
	at 
org.apache.axis.configuration.FileProvider.getDeployedServices(FileProvider.java:322)
	at 
org.apache.axis.transport.http.AxisServlet.reportAvailableServices(AxisServlet.java:584)
	at org.apache.axis.transport.http.AxisServlet.doGet(AxisServlet.java:256)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
	at 
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:335)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at 
com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
	at com.caucho.server.http.Invocation.service(Invocation.java:315)
	at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
	at 
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164)
	at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
	at java.lang.Thread.run(Thread.java:536)

Thank you.

Best regards,
Daniel

_________________________________________________________________
Download ringtones, logos and picture messages from MSN Malaysia 
http://www.msn.com.my/mobile/ringtones/default.asp

Reply via email to