JNA example program java.lang.NoClassDefFoundError

前端 未结 3 1052
梦如初夏
梦如初夏 2021-01-19 15:43

I can compile this JNA example code (from step 2 of https://github.com/twall/jna/#getting_started):

package com.sun.jna.examples;

import com.sun.jna.Library         


        
相关标签:
3条回答
  • 2021-01-19 16:03

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

    0 讨论(0)
  • 2021-01-19 16:14

    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.

    0 讨论(0)
  • 2021-01-19 16:27

    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.

    0 讨论(0)
提交回复
热议问题