This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/Element  RSS feed

 
karthik swamy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am getting subjected error even if there is class file present so please help me out of this ..

following is my java code :

package   pkh.kky;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

public class PDFWriter{

   /**
    * @param args
    */
   public static void main(String[] args) {
       try {
           File file = new File("/home/hdfc/jboss-eap-6.4/standalone/deployments/ICM_UNB.war/WEB-INF/classes/interchange/dataobject/itext.pdf");
           FileOutputStream pdfFileout = new FileOutputStream(file);
           Document doc = new Document();
           PdfWriter.getInstance(doc, pdfFileout);

           doc.addAuthor("QuicklyJava.com");
           doc.addTitle("This is title");
           doc.open();

           Paragraph para1 = new Paragraph();
           para1.add("This is paragraph 1");

           Paragraph para2 = new Paragraph();
           para2.add("This is paragraph 2");

           doc.add(para1);
           doc.add(para2);

           doc.close();
           pdfFileout.close();

           System.out.println("Success!");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

}
 
Jeanne Boyarsky
author & internet detective
Posts: 39235
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you running that program at the command line or through JBoss? IF the former, do you have itext.jar in your classpath?
 
karthik swamy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running this code through command in jboss server.
I compiled using javac -cp $CLASSPATH: and then the lib path and class also got compiled without any error but still it gives the same error.
So please hekp me out
 
Jeanne Boyarsky
author & internet detective
Posts: 39235
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right so it compiles. The problem is at runtime. Have you added the jar to JBoss' runtime classpath?
 
harshdeep puri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have fixed the above problem.Here problem with Classloader. we can overcome this by placing jar file in web-inf/lib/ext folder. Probably we could not seen this.It is the secondary loaction for classloader to load the jars or third party files. further deatils go through this url:

https://javarevisited.blogspot.com/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!