JNA example program java.lang.NoClassDefFoundError

前端 未结 3 1054
梦如初夏
梦如初夏 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: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.

提交回复
热议问题