External jar file problem (TIKA)

I expect you may be experiencing a “class conflict” with the older version of Tika in Lucee which as we know doesn’t work. Even though you’ve put the newer Tika app jar in your /lib folder, Lucee will have already loaded the older version and will be using that - hence no change to the results.

JavaLoader can solve that problem, but it might first be worth trying the “OSGi” approach that Lucee 5 offers and which is also designed to avoid class conflicts. Brad has a good blog post about this, which you should read first, then try the following which is based on his advice:

  1. Use 7-zip to open up the tika-app-1.23.jar you downloaded (right click-click the jar and choose 7-zip > Open Archive)
  2. Find the file META-INF/MANIFEST.MF, right-click it and choose Edit.
  3. Add the following to the end of the file contents:
Bundle-Name: Apache Tika App Bundle
Bundle-SymbolicName: apache-tika-app-bundle
Bundle-Description: Apache Tika App jar converted to an OSGi bundle
Bundle-ManifestVersion: 2
Bundle-Version: 1.23
  1. Save and close the file, choosing to update the archive when prompted by 7-zip
  2. The jar is now an OSGi bundle and can be dropped into your Lucee installation’s lucee-server/bundles folder.
  3. Check the new bundle is available in your Lucee server admin UI under Info > Bundle (jar)

Assuming that works, try this code in your app:

tika = CreateObject( "java", "org.apache.tika.Tika", "apache-tika-app-bundle" );
filePath = "[FullFilePathToMy].pdf"; //e.g. "C:\temp\my.pdf"
try{
    fileStream = CreateObject( "java","java.io.FileInputStream" ).init( JavaCast( "string", filePath ) );
    result = tika.parseToString( fileStream );
}
finally{
    fileStream.close();
}
dump( result );
2 Likes