iText and org.bouncycastle.asn1.ASN1Primitive not found

phrfpeixoto picture phrfpeixoto · Dec 26, 2012 · Viewed 18.1k times · Source

I'm a newbie on iText. This is my first project using this library.

I'm building a PDF with essentially a big table on it, and while compiling, i'm getting this Class Not Found error: class file for org.bouncycastle.asn1.ASN1Primitive not found

I'm confused, since i'm only using the basic functionalities, and didn't even touch the PDF Signing features. What should i do to fix the error?

I'm using:

  • JDK 1.7
  • iText 5.3.5
  • extrajars 2.2 (which provides bcmail-jdk15-146.jar, bcprov-jdk15-146.jar and bctsp-jdk15-146.jar)

I only using iText inside one class, with these imports:

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

If it helps, i would like to clarify that when i run the project inside NetBeans, it compiles and runs just fine. The error appears when i try to compile it to a single executable jar file (which includes the dist/lib)

This is build.xml target where the error appears:

<target name="single_jar" depends="jar">

    <property name="store.jar.name" value="Final"/>

    <property name="store.dir" value="store"/>
    <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>

    <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>

    <delete dir="${store.dir}"/>
    <mkdir dir="${store.dir}"/>

    <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
        <zipgroupfileset dir="dist" includes="*.jar"/>
        <zipgroupfileset dir="dist/lib" includes="*.jar"/>

        <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
        </manifest>
    </jar>

    <zip destfile="${store.jar}">
        <zipfileset src="${store.dir}/temp_final.jar"
        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
    </zip>

    <delete file="${store.dir}/temp_final.jar"/>

</target>

Answer

mkl picture mkl · Dec 26, 2012

Current iText versions (since 5.3.0) use BouncyCastle 1.47 but you provide 1.46; even though that looks like a small step, there are substantial changes between those BC versions; any sensible version management would have called it 2.0.

Please update dependencies.