the problems with read Doc or Docx file in java [c

2019-03-07 08:38发布

问题:

I am having this problem with reading a .doc or .docx file in Java:

java.lang.NoClassDefFoundError: org/apache/poi/hwpf/HWPFDocument

I don't understand why this is happening and would appreciate any help getting rid of this error.

回答1:

Well, that sounds like you haven't put the relevant Apache POI jar file(s) into the classpath you're using at execution time. Without more information, that's about all we can say.

  • Find out which jar files are required
  • Find out what's controlling your classpath (which will depend on what kind of app you're running)
  • Make sure all the jar files are in place
  • Rerun
  • Profit :)

For example, from the command line, on Windows, you might want to run:

java -cp .;poi-whatever.jar foo.bar.Test

(Replace the jar file name and your entry point name appropriately.)