Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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

 
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();
       }
   }

}
 
author & internet detective
Posts: 39957
804
Eclipse IDE VI Editor Java
  • 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: 39957
804
Eclipse IDE VI Editor Java
  • 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?
 
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
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic