0
votes

I'm trying to create a PDF file using iText 7.1.9 jar in Java. But I'm getting below exception. I have all necessary steps to compile jars, set class path and build path. Please help me resolve this.

java.lang.NoClassDefFoundError: com/itextpdf/kernel/pdf/PdfDocument

in line pdfdoc = new PdfDocument(new PdfReader(file));. My POM.xml for Vaadin8/Maven is as below. In properties tag:

<itext.version>RELEASE</itext.version> 

And in dependencies I have added below entry:

<!-- https://mvnrepository.com/artifact/com.itextpdf/itext7-core -->
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext7-core</artifactId>
    <version>7.1.9</version>
    <type>pom</type>    
</dependency>

I have built all jars using command line as mvn deploy:deploy-file -Dfile=/barcodes-7.1.9.jar -DgroupId=com.roufid.tutorials -DartifactId=example-app -Dversion=1.0 -Dpackaging=jar -Durl=file:./maven-repository/ -DrepositoryId=maven-repository -DupdateReleaseInfo=true

1
Is this possibly because you have specified only the pom as the type? If you remove that does it recognize class? Additionally are you sure that you have have refreshed your project and bundled the itext7-core jar when running the code? Maybe you could provide a bit more detail on how you are running this? - Tristan
tried removing POM but no help. This is Vaadin8, Mavan project. - Datta Dhonde
From what you added and what @HasS noted below. It looks like you are bundling that as a jar which will not have the dependencies included with it. When running that code you will need to set the other jars on the classpath. I'm guessing that if you run this in a unit test it would not fail. - Tristan

1 Answers

0
votes

This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.