Skip to main content
Inspiring
August 1, 2008
Answered

POI-HWPF Not Working

  • August 1, 2008
  • 2 replies
  • 1696 views
I'm trying to get POI-HWPF working with ColdFusion so I can read and extract text from Word documents. We don't have MS Office installed on the server so we can't use the filesystem object and COM.

I have the POI, POI-Contrib, and POI-Scratchpad JAR files installed on the server and I added them to the class path through the ColdFusion Administrator.

The following code works fine until it gets to the line where it instantiates the HWPFDocument object. Once it gets there it throws an "Object Instantiation Exception: An exception occurred when instantiating a Java object. The class must not be an interface or an abstract class. Error: ''.

Any help would be greatly appreciated!
    This topic has been closed for replies.
    Correct answer -__cfSearching__-
    darbus23 wrote:
    > From the error message it appears that it can find the class.

    Edit: See correction below

    > Any ideas how I could modify ColdFusion to use the 3.1 jars?

    You could use the JavaLoader.cfc to dynamically load the jar. It works well. However, you should store it in the server scope to avoid a known JVM memory leak issue.
    http://javaloader.riaforge.org/

    2 replies

    -__cfSearching__-Correct answer
    Inspiring
    August 1, 2008
    darbus23 wrote:
    > From the error message it appears that it can find the class.

    Edit: See correction below

    > Any ideas how I could modify ColdFusion to use the 3.1 jars?

    You could use the JavaLoader.cfc to dynamically load the jar. It works well. However, you should store it in the server scope to avoid a known JVM memory leak issue.
    http://javaloader.riaforge.org/
    Inspiring
    August 1, 2008
    darbus23 wrote:
    > From the error message it appears that it can find the class.

    I misread that. I thought you said it _cannot_ find the class.

    Anyway I just loaded the 3.1 jar into the classpath and tried it again and got an exception. So the problem is having two versions of the jar in the classpath. You can use the javaLoader to get around that issue.


    Unable to find a constructor for class org.apache.poi.hwpf.HWPFDocument that accepts parameters of type ( org.apache.poi.poifs.filesystem.POIFSFileSystem ).




    Inspiring
    August 1, 2008
    darbus23 wrote:
    > I have the POI, POI-Contrib, and POI-Scratchpad JAR files
    > installed on the server and I added them to the class path through
    > the ColdFusion Administrator.

    1. What version of CF and POI are you using ?
    2. Did you restart the server after installing the jars ? A restart is required for CF to detect new jars in the classpath.

    > Once it gets there it throws an "Object Instantiation Exception:
    > An exception occurred when instantiating a Java object.

    What is the error message in the stack trace ? It should be more informative.
    darbus23Author
    Inspiring
    August 1, 2008
    We're using ColdFusion version 8.0.1 and POI 3.1. I restarted the server after I installed the jars and I was able to read an Excel file with HSSF but not Word files with HWPF. Where would I find the stack trace at?
    Inspiring
    August 1, 2008
    darbus23 wrote:
    > Where would I find the stack trace at?

    If you have enabled debugging in the CF Administrator it should be displayed as a link at the bottom of the error message. You can also find the information in the CF error logs: {cf_root}\logs

    > We're using ColdFusion version 8.0.1

    I recently learned ColdFusion 8 ships with a POI jar, version 2.5 I believe. Loading a second version of the jar into the class path may cause a conflict. CF will only see one version of the jar and it will probably be the older one. I took a look at CF's POI jar. It does not appear to contain the "hwpf" package. So that might be your problem. But see what the stack trace message says first.