0

I am developing a Java application but I am getting a java.lang.NoClassDefFoundError. I have checked everything I can think of:

  • The jar file exists in the directory and is not 0 bytes
  • The jar file has the same permissions as all other jar files (I have shown this with ls -la cmmand)
  • The jar file contains the exact class that is reported as missing (I have shown this in output with the jar tf command)
  • jar file is specified in the command string under the -cp option I have changed the order of jars in class path and the other
  • jar files are recognised - otherwise the other parts of the program wouldn't work
  • It is the same jar file I am building against
  • Project works in eclipse on my laptop

It just doesn't work in my RaspberryPi.

I have to add something else to my checklist debugging of ClassNotFound errors. Does anyone have any suggestions?

I have the listing of the output of the checks I have run below.

pi@pi-raspbian-main ~/personal_services $ java -cp /home/pi/personal_services/Console/Console.jar:/home/pi/personal_services/lib/Library.jar:/home/pi/personal_services/lib/JavaCommon.jar:/home/pi/personal_services/lib/sqlite-jdbc-3.7.2.jar:/home/pi/personal_services/lib/commons-codec-1.10.jar metcarob.com.personalservices.console.Main /home/pi/personal_services/Console/ConsoleSettings.xml ListNodes
EVALUATING ListNodes
CONNECTING
Exception in thread "ConnectionThread" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at metcarob.com.common.network.xmlprotocol.ConnectionSocketContainer.ProcessIncommingMessages(Unknown Source)
    at metcarob.com.common.network.xmlprotocol.Connection.processIncomingMessages(Unknown Source)
    at metcarob.com.common.network.xmlprotocol.Connection.runDER(Unknown Source)
    at metcarob.com.common.thread.CloseableThread.run(Unknown Source)
RUNNING ListNodes
Closing connection
Closing connection
DONE
pi@pi-raspbian-main ~/personal_services $ jar tf /home/pi/personal_services/lib/commons-codec-1.10.jar | grep Base64
org/apache/commons/codec/binary/Base64.class
org/apache/commons/codec/binary/Base64InputStream.class
org/apache/commons/codec/binary/Base64OutputStream.class
pi@pi-raspbian-main ~/personal_services $ ls -la /home/pi/personal_services/lib/commons-codec-1.10.jar
-rw-r--r-- 1 pi pi 284184 Apr  3 20:54 /home/pi/personal_services/lib/commons-codec-1.10.jar

Thanks Robert

Robert3452
  • 1,354
  • 2
  • 17
  • 39
  • quite interesting... what jdk version the jar using? – user390525 Apr 03 '15 at 23:14
  • Did you check http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java – abRao Apr 03 '15 at 23:16
  • The raspberry Pi has java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode) in eclipse on my laptop I am building against jdk 1.7. Should this matter? It doesn't seem to with other jar files – Robert3452 Apr 03 '15 at 23:21
  • @Robert3452 Is that all stack traces that your program shows? because it's not `ClassNotFoundException` so there is possibility that the jvm did found the lib but failed to load it. – kucing_terbang Apr 04 '15 at 08:19

1 Answers1

0

I have discovered the cause of my problem.

I have main app in: Console.jar Which used a utiliy jar: JavaCommon.jar which used: commons-codec-1.10.jar

When I built JavaCommon.jar I provided a class path which contained commons-codec-1.10.jar and it compiled without a problem

When I built Console.jar I provided a class path which contained JavaCommon.jar but did not contain commons-codec-1.10.jar and it compiled without a problem

Then when I ran my app I provided a classpath which contained all the jars but I still got the NoClassDefFoundError Exception

When I changed the build so I built Console.jar with a classpath containing all the jars again it compiled and ran without a problem.

Robert3452
  • 1,354
  • 2
  • 17
  • 39