apache POI java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52381075/
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-11 00:26:08  来源:igfitidea点击:

apache POI java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile

javaapacheapache-poi

提问by Juliar Nasution

I try to make word document using Apache POI 4.0.0, but i get error

我尝试使用 Apache POI 4.0.0 制作 word 文档,但出现错误

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:365) at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:158) at org.apache.poi.xwpf.usermodel.XWPFDocument.(XWPFDocument.java:149) at model.Model_dokumen.Cetak(Model_dokumen.java:32) at view.Frame_surat.cetak_dan_simpanActionPerformed(Frame_surat.java:414) at view.Frame_surat.access$400(Frame_surat.java:23) at view.Frame_surat$5.actionPerformed(Frame_surat.java:211) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6533) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6298) at java.awt.Container.processEvent(Container.java:2238) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2296) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475) at java.awt.Container.dispatchEventImpl(Container.java:2282) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:733) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:730) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 43 more Blockquote

线程“AWT-EventQueue-0”中的异常 java.lang.NoClassDefFoundError: org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:365) 处的 org/apache/commons/compress/archivers/zip/ZipFile在 org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:158) 在 org.apache.poi.xwpf.usermodel.XWPFDocument.(XWPFDocument.java:149) 在 model.Model_dokumen.Cetak(Model_dokumen. java:32) at view.Frame_surat.cetak_dan_simpanActionPerformed(Frame_surat.java:414) at view.Frame_surat.access$400(Frame_surat.java:23) at view.Frame_surat$5.actionPerformed(Frame_surat.java:211) at javax.swing。 AbstractButton.fireActionPerformed(AbstractButton.java:2022) 在 javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) 在 javax.swing。DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在 javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在 javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在 java.awt.Component .processMouseEvent(Component.java:6533) 在 javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 在 java.awt.Component.processEvent(Component.java:6298) 在 java.awt.Container.processEvent(Container. java:2238) 在 java.awt.Component.dispatchEventImpl(Component.java:4889) 在 java.awt.Container.dispatchEventImpl(Container.java:2296) 在 java.awt.Component.dispatchEvent(Component.java:4711) 在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897) 在 java.awt.LightweightDispatcher。processMouseEvent(Container.java:4534) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475) at java.awt.Container.dispatchEventImpl(Container.java:2282) at java.awt.Window.dispatchEventImpl(Window.java) :2746) 在 java.awt.Component.dispatchEvent(Component.java:4711) 在 java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) 在 java.awt.EventQueue.access$500(EventQueue.java:97) 在java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) 在 java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) 在 java.awt.EventQueue$4.run(EventQueue.java:733) 在 java.awt.EventQueue$4.run(EventQueue.java:731) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.security .ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) 在 java.awt.EventQueue.dispatchEvent(EventQueue.java:730) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) 在 java.awt.EventDispatch pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpThread.java:101 :93) 在 java.awt.EventDispatchThread。run(EventDispatchThread.java:82) 由:java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang。 ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 43 更多 Blockquote43 更多块报价43 更多块报价

i following tutorial from this site : tutorials point, and i had trying any solutions from blog, forum, etc. but nothing works for me. This is my code :

我正在关注这个网站的教程教程点,我尝试了博客、论坛等的任何解决方案,但对我来说没有任何效果。这是我的代码:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import view.Frame_surat;

/**
 *
 * @author nasution
 */
public class Model_dokumen {

    public void Cetak(Frame_surat fs) throws Exception {
        try {
            XWPFDocument document = new XWPFDocument();
//            XWPFDocument document = new XWPFDocument();//blank document
            //membuat paragraf

             //membuat dokumen surat keluar
            try (FileOutputStream outputStream = new FileOutputStream(new File("Surat_keluar.docx"))) {
                //membuat paragraf
                XWPFParagraph paragraf = document.createParagraph();
                XWPFRun run = paragraf.createRun();
                run.setText("ini adalah halaman dokumen yg baru saja dibuat menggunakan POI");
                document.write(outputStream);
            }
            JOptionPane.showMessageDialog(null, "Surat keluar berhasil dibuat");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

采纳答案by Sparks

Try searching for the class name then jar download you might find the specified jar files. "ex: XWPF jar files download." and download the classes of XWPF as jar files i got this problem before and I solved it like this but for me it was pdfBox. PS: Try searching for jar files for "org.apache.poi.xwpf" you will get more results.

尝试搜索类名,然后 jar 下载您可能会找到指定的 jar 文件。“例如:XWPF jar 文件下载。” 并将 XWPF 的类下载为 jar 文件,我之前遇到过这个问题,我是这样解决的,但对我来说它是 pdfBox。PS:尝试搜索“org.apache.poi.xwpf”的jar文件,你会得到更多的结果。

回答by Chris Liston

For poi-4.1.0 I had to add these to the classpath: dom4j-1.6.jar xmlbeans-3.1.0.jar commons-collections4-4.3.jar commons-compress-1.18.jar Only then did this work for Excel.xlsx File:

对于 poi-4.1.0,我必须将这些添加到类路径中: dom4j-1.6.jar xmlbeans-3.1.0.jar commons-collections4-4.3.jar commons-compress-1.18.jar 然后才对 Excel.xlsx 起作用文件:

ExcelWBook = new XSSFWorkbook(ExcelFile);