• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

java.lang.NoClassDefFoundError in a jar

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application in Eclipse that runs fine in Eclipse. I have been testing it as a jar file for some time, but today I got the error java.lang.NoClassDefFoundError. After browsing the Internet I have found many discussions but no solution; I have also read answers to similar questions in this forum. Please tell me what do I have to look inside the jar file or what log do I have to look into.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Further clarification. The error I receive when executing a batch file with contents "java -jar paperless.jar" is "java.lang.NoClassDefFoundError: org/objenesis/Objenesis"; however, after I unzipped the jar file the file ".classpath" contains:

After unzipping objenesis-2.6.jar I found out that the class is there.
 
Sheriff
Posts: 22816
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.classpath only works inside Eclipse. When you run your JAR outside of it the file has no meaning at all. Instead you should use META-INF/MANIFEST.MF to add a Class-Path entry: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html. Note that these dependencies cannot be located inside your JAR file, because the class loader won't be able to find them there. The best is to use a relative path, and ship the JARs with your own JAR inside a ZIP file. Make sure that you are allowed to though, some libraries may prohibit this.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your prompt reply. I have no intention of using the classpath; I only posted what is in the jar file. The jar file is created by Eclipse and until yesterday it was working fine. If worse comes to worse, I am willing to modify the jar file, but someone has to tell me how.
 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Few questions

1. How you run the jar file, using command prompt or using IDE
2. If run thru command prompt, can you whats the classpath variable points to.
3. For which class it is throwing NoClassDefFoundError.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer all the questions; this is what I get running the jar file:

C:\Workspaces\JAR Files>java -jar paperless.jar
java.lang.NoClassDefFoundError: org/objenesis/Objenesis
       at com.paperless.main.PropertiesDialog.dbFileOk(PropertiesDialog.java:184)

As I mentioned in a previous response, org/objenesis/Objenesis class shows in the jar file after I unzipped it.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Barrero wrote:
As I mentioned in a previous response, org/objenesis/Objenesis class shows in the jar file after I unzipped it.



Your previous response mentioned that you unzipped a different jar file ... and Rob mentioned that you need to modify the manifest to point to that different jar file. Are you now saying that the class exists in the paperless jar file that is executed?

Henry
 
Lakshman Arun
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How you are referring Objenesis , with fully package name or just Objenesis inside your PropertyFile class
 
Lakshman Arun
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typo PropertiesDialog class
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all; I solved the problem by unzipping objenesis-1.2.jar and added the code to the project.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not really a solaution, it's more a bit of sticky tape over the problem.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic