Java 从所需的 .class 文件间接引用,即使构建路径设置正确 apache POI ..?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24134676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 10:23:11  来源:igfitidea点击:

Indirectly referenced from required .class file, even the build path is set correctly apache POI..?

javaeclipseubuntuapache-poibuildpath

提问by roanjain

import java.io.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import org.apache.poi.hwpf.usermodel.HeaderStories;

public class ReadDocFileInJava {

   public static void main(String[] args) 
   {
      /**This is the document that you want to read using Java.**/
      String fileName = "C:\Documents and Settings\kushalp\Desktop\Test.doc";

      /**Method call to read the document (demonstrate some useage of POI)**/
      readMyDocument(fileName);
   }
   public static void readMyDocument(String fileName)
   {
         POIFSFileSystem fs = null;
         try 
         {
             fs = new POIFSFileSystem(new FileInputStream(fileName));
             HWPFDocument doc = new HWPFDocument(fs);

             /** Read the content **/
             readParagraphs(doc);

             int pageNumber=1;

             /** We will try reading the header for page 1**/
             readHeader(doc, pageNumber);

             /** Let's try reading the footer for page 1**/
             readFooter(doc, pageNumber);

             /** Read the document summary**/
             readDocumentSummary(doc);

         } 
         catch (Exception e) 
         {
             e.printStackTrace();
         }
   }  

   public static void readParagraphs(HWPFDocument doc) throws Exception
   {
       WordExtractor we = new WordExtractor(doc);

       /**Get the total number of paragraphs**/
       String[] paragraphs = we.getParagraphText();
       System.out.println("Total Paragraphs: "+paragraphs.length);

       for (int i = 0; i < paragraphs.length; i++) 
       {

            System.out.println("Length of paragraph "+(i +1)+": "+ paragraphs[i].length());
            System.out.println(paragraphs[i].toString());
       }
   }

   public static void readHeader(HWPFDocument doc, int pageNumber)
   {
       HeaderStories headerStore = new HeaderStories( doc);
       String header = headerStore.getHeader(pageNumber);
       System.out.println("Header Is: "+header);
   }

   public static void readFooter(HWPFDocument doc, int pageNumber)
   {
       HeaderStories headerStore = new HeaderStories( doc);
       String footer = headerStore.getFooter(pageNumber);
       System.out.println("Footer Is: "+footer);
   }

   public static void readDocumentSummary(HWPFDocument doc) 
   {
       DocumentSummaryInformation summaryInfo=doc.getDocumentSummaryInformation();
       String category = summaryInfo.getCategory();
       String company = summaryInfo.getCompany();
       int lineCount=summaryInfo.getLineCount();
       int sectionCount=summaryInfo.getSectionCount();
       int slideCount=summaryInfo.getSlideCount();

       System.out.println("---------------------------");
       System.out.println("Category: "+category);
       System.out.println("Company: "+company);
       System.out.println("Line Count: "+lineCount);
       System.out.println("Section Count: "+sectionCount);
       System.out.println("Slide Count: "+slideCount);

   }

I am getting error in these two packages

我在这两个包中遇到错误

import org.apache.poi.poifs.filesystem.*;

导入 org.apache.poi.poifs.filesystem.*;

import org.apache.poi.hpsf.DocumentSummaryInformation;

导入 org.apache.poi.hpsf.DocumentSummaryInformation;

The type org.apache.poi.poifs.filesystem.POIFSFileSystem cannot be resolved. It is indirectly referenced from required .class files

类型 org.apache.poi.poifs.filesystem.POIFSFileSystem 无法解析。它是从所需的 .class 文件间接引用的

I have attached a snapshot my java build path...since the program require

我附上了我的 java 构建路径的快照...因为程序需要

poi-scratchpad-3.2-FINAL-20081019.jar

poi-scratchpad-3.2-FINAL-20081019.jar

It is correctly set in java build path..then why I am getting such error ..help..!!enter image description here

它在java构建路径中正确设置..那么为什么我会收到这样的错误..帮助..!!在此处输入图片说明

enter image description here

在此处输入图片说明

回答by roanjain

found the solution it requires poi-3.7.jar

找到它需要的解决方案 poi-3.7.jar

http://mvnrepository.com/artifact/org.apache.poi/poi/3.7

http://mvnrepository.com/artifact/org.apache.poi/poi/3.7

回答by Gagravarr

You have two problems. One is that you're using Apache POI 3.2, which dates from 6 years agoand there have been a huge number of bug fixes since then

你有两个问题。一个是您使用的是6 年前的Apache POI 3.2,从那时起已经修复大量错误

Second problem, you've missed some of the POI jars and their dependencies. See the components page for details. Basically though, to use HWPF, you need boththe poiandpoi-scratchpadjars on your classpath

第二个问题,您错过了一些 POI jar 及其依赖项。有关详细信息,请参阅组件页面。基本上,要使用 HWPF,您需要在类路径上同时使用poipoi-scratchpadjar

回答by Swapnil Patil

delete entire released directories located at C:\Users\user\.m2\repository\org\apache\poi.

删除位于 的整个已发布目录C:\Users\user\.m2\repository\org\apache\poi

Right Click on project > Maventhen Update project.

project > Maven然后右键单击Update project