NoSuchMethodError custom Java action with pdfbox

0
Maybe someone can help me. I'm creating a custom java action to extra text from a pdf file. I'm using the already installed pdfbox jar, which is included by the CommunityCommons module. In the custom java action I am calling `PDDocument.load(Core.getFileDocumentContent(getContext(), __Parameter));` but when trying to execute the java action I get the following error: `java.lang.NoSuchMethodError: 'org.apache.pdfbox.pdmodel.PDDocument org.apache.pdfbox.pdmodel.PDDocument.load(java.io.InputStream)'`.   According to the documentation the method should exists. It is also used by the CommunityCommons "Overlay pdf document", which I also tried and gotten the same result.    I have already checked the userlib for duplicate jar files, but there aren't any duplicate jar files. Also I have tried "Synchronize dependencies" and "Deploy for eclipse" multiple times without any result.   Does anyone have any idea where the problem might lie? I also tried update the pdfbox jar to v 3.x.x, but that resulted in the CommunityCommons breaking.
asked
3 answers
1

Do you also have a copy of the pdfbox-X.X.X.jar in your vendorlib folder? If you do, keep this, and delete the pdfbox.jar in your userlib folder.

 

How are you compiling your Java actions? If you aren't already, just build your application in Mendix Studio Pro rather than using Eclipse or another external tool. It will compile the Java actions as it builds the Mendix application.

 

Good luck!

answered
1

It said "No such Method Error" and during runtime

If its related to relevant dependency not found, then it would give a compilation error, when building the project.

 

This is a runtime error, which means, the required dependency if found while compiling, but not when running. Thats possible, because the class was found in classpath. But in runtime, there are multiple such classes and JRE dynamically loads that similar class without the method.

 

There seems to be some other jar file, not specifically PDFBox, but some other jar file which has same class but different method signature. And during runtime, this class is being called, which returns this error. You need to find that jar file (dependency) that has this conflicting class.

  • It could be different version of PDFBox, which you confirmed not the case
  • OR some other jar, with same classname 

In eclipse, if you remove the imports, then it is possible with CTRL+SPACEBAR to see all relevant classes available in class path. Check if you have the same class in different jar and then you can take relevant actions.

answered
0

`PDDocument.load(Core.getFileDocumentContent(getContext(), __Parameter));`

 

Are you making a typo? shouldn't it be starting with PDF? It's weird that it's not PDFDocument

 

Just asking, maybe this is not it but it's worth double checking. 

answered