• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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
Marshal
Posts: 35736
412
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
Marshal
Posts: 35736
412
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!