0

I know this question has been asked before but I tried the solutions given in other Threads with no success.

Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/i2c
/I2CFactory at com.jksoft.rpi.dashpi.pishock.Sensor.setup(Sensor.java:32)

on my windows machine i used maven to get the pi4j dependency and for the I ran the curl statemet shown here (curl -s get.pi4j.com | sudo bash) an then tried to add the classes to the classpath with the command shown on that site: (sudo java -classpath .:classes:/opt/pi4j/lib/'*' ...) In my case:

sudo java -classpath .:classes:/opt/pi4j/lib/'*':. -jar DashPi-1.0-SNAPSHOT.jar

but it still gives me that error and I dont know whats wrong.

Maybe this happens because pi4j has been installed unter

/opt/pi4j

and my jar is at

/home/pi

Any help would be appreciated!

the code looks as follows:

public Sensor(){
    this.setup();
}

private void setup(){
    try {
        this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
        this.device = this.bus.getDevice(0x53);
    } catch (IOException ex) {
        Logger.getLogger(Sensor.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Jan Kressin
  • 115
  • 1
  • 9

1 Answers1

0

Why are you using the wildcard on that call? It seems that the classpath is wrong and should be something like:

sudo java -classpath .:classes:/opt/pi4j/lib/:. -jar DashPi-1.0-SNAPSHOT.jar
ludiccc
  • 321
  • 2
  • 10