JNA example program java.lang.NoClassDefFoundError

爱⌒轻易说出口 提交于 2019-12-01 19:47:02

This example (as well as vast majority of java classes) uses packages:

package com.sun.jna.examples;

In order to compile / run it properly you need to run javac / java from the "root" folder (e.g. folder where "com" is located):

Let's say you have a folder called examples. You'd put both the jna.jar and the source code in it preserving folder structure:

/examples
 jna.jar
 /com
   /sun
      /jna
         /examples
           HelloWorld.java

You compile and run using:

javac -classpath .:jna.jar -g com/sun/jna/examples/HelloWorld.java

java -classpath .:jna.jar com.sun.jna.examples.HelloWorld

Note the path separators in the former case and dots in the latter.

Either just remove this line and recompile (which is fine in this case as you just try out some sample)

package com.sun.jna.examples;

or read up on what packages in java are and how they have to be handled (ChssPly76s Posts as a starter).

Better choose the second option as sooner or later (probably sooner) you will have to deal with packages anyway. So just take the time now to read up on it.

Sergio

Here is a good example (in Spanish), http://bdevmex.blogspot.mx/2013/01/comunicar-aplicaciones-mediante-jna.html I hope that this can help you

user2408280

In Eclipse, under Java Build path > Order and export, select export jna.jar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!