Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

POI-HWPF Not Working

Explorer ,
Aug 01, 2008 Aug 01, 2008
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!
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Aug 01, 2008 Aug 01, 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/
Translate
Valorous Hero ,
Aug 01, 2008 Aug 01, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2008 Aug 01, 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 01, 2008 Aug 01, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2008 Aug 01, 2008
The log file doesn't give me any additional information. From the error message it appears that it can find the class it just bombs when it tries to instantiate it. But you're explanation does make sense to why the Excel works but not Word since the Excel functionality has been around for awhile with POI. Any ideas how I could modify ColdFusion to use the 3.1 jars?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 01, 2008 Aug 01, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 01, 2008 Aug 01, 2008
LATEST
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 ).




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources