Program Tip

java.util.zip.ZipException : zip 파일 열기 오류

programtip 2020. 10. 30. 20:31
반응형

java.util.zip.ZipException : zip 파일 열기 오류


다른 중첩 된 Jar를 포함하는 Jar 파일이 있습니다. JarFile()이 파일 에서 새 생성자를 호출하면 다음과 같은 예외가 발생합니다.

java.util.zip.ZipException : zip 파일 열기 오류

이 Jar 파일의 내용을 수동으로 압축 해제하고 다시 압축하면 정상적으로 작동합니다.

이 예외는 WebSphere 6.1.0.7 이상 버전에서만 볼 수 있습니다. 바람둥이와 WebLogic에서도 똑같은 것이 잘 작동합니다.

JarFile 대신 JarInputStream을 사용하면 예외없이 Jar 파일의 내용을 읽을 수 있습니다.


jar 파일이 손상되지 않았는지 확인하십시오. 손상되었거나 압축을 풀 수없는 경우이 오류가 발생합니다.


나는 같은 문제에 직면했다. java.util.zip.ZipFile이 처리 할 수없는 zip 아카이브가 있었지만 WinRar가 잘 풀었습니다. SDN 에서 Java의 압축 및 압축 해제 옵션에 대한 기사를 찾았습니다 . 마지막으로 아카이브를 처리 할 수있는 메서드를 생성하기 위해 예제 코드 중 하나를 약간 수정했습니다. 트릭은 ZipFile 대신 ZipInputStream을 사용하고 zip 아카이브를 순차적으로 읽는 것입니다. 이 방법은 빈 zip 아카이브를 처리 할 수도 있습니다. 모든 zip 클래스에는 .jar 아카이브에 대해 동등한 하위 클래스가 있으므로 필요에 맞게 방법을 조정할 수 있다고 생각합니다.

public void unzipFileIntoDirectory(File archive, File destinationDir) 
    throws Exception {
    final int BUFFER_SIZE = 1024;
    BufferedOutputStream dest = null;
    FileInputStream fis = new FileInputStream(archive);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;
    File destFile;
    while ((entry = zis.getNextEntry()) != null) {
        destFile = FilesystemUtils.combineFileNames(destinationDir, entry.getName());
        if (entry.isDirectory()) {
            destFile.mkdirs();
            continue;
        } else {
            int count;
            byte data[] = new byte[BUFFER_SIZE];
            destFile.getParentFile().mkdirs();
            FileOutputStream fos = new FileOutputStream(destFile);
            dest = new BufferedOutputStream(fos, BUFFER_SIZE);
            while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
            fos.close();
        }
    }
    zis.close();
    fis.close();
}

log4j와 관련이있을 수 있습니다.

websphere Java 클래스 경로 (시작 파일에 정의 된대로)와 애플리케이션 클래스 경로에 log4j.jar 파일이 있습니까?

log4j.jar 파일이 java 클래스 경로에 있고 webapp의 web-inf / lib 디렉토리에 없는지 확인하는 경우.


또한 개미 버전 과 관련이있을 수도 있습니다 (귀하의 경우가 아닐 수도 있지만 여기에 참고 용으로 넣었습니다).

클래스 경로에 .class 파일이 있습니다 (예 : 디렉토리 또는 .jar 파일이 아님). ant 1.6부터 ant는 매니페스트 항목을 확인하는 클래스 경로의 파일을 엽니 다. 이 시도는 "java.util.zip.ZipException"오류와 함께 실패합니다.

ant 1.5에서는 파일을 열려고하지 않기 때문에 문제가 발생하지 않습니다. -따라서 클래스 경로에 .class 파일이 포함되어 있지 않은지 확인하십시오.


참고로, 별도의 항아리 를 고려 했 습니까?
메인 항아리의 매니페스트에서 다음 속성을 사용하여 다른 항아리를 참조 할 수 있습니다.

Class-Path: one.jar two.jar three.jar

그런 다음 모든 병을 같은 폴더에 넣으십시오.
다시 말하지만, 귀하의 경우에는 유효하지 않을 수 있지만 참조를 위해 여전히 존재합니다.


JVM이 임시 디렉토리로 간주하는 모든 것이 거기에 없거나 쓰기 권한이 없어서 액세스 할 수 없을 때이 예외를 본 적이 있습니다 .


jboss-xyz / server [config] / tmp 및 jboss-xyz / server / [config] / work 디렉토리를 삭제하여이 문제를 해결했습니다.


나는 때문에 손상된의 문제에 직면 ZIP 필즈 아이를

JAR 파일이 완전히 다운로드 되었는지 확인 하십시오.


또한 기록중인 파일 시스템의 디스크 공간이 부족한 경우에도이 오류가 표시됩니다. 따라서 더 많은 공간을 제공하거나 로그 파일을 정리할 수 있습니다.


Java 6을 사용하는 특정 Zip 파일로 이것을 보았지만 Java 8로 업그레이드하면 사라 졌으므로 (Java 7을 테스트하지 않음) Java에서 최신 버전의 ZipFile이 더 많은 압축 알고리즘을 지원하므로 파일을 읽을 수 있습니다. 이전 버전에서는 실패합니다.


Liquibase was getting this error for me. I resolved this after I debugged and watched liquibase try to load the libraries and found that it was erroring on the manifest files for commons-codec-1.6.jar. Essentially, there is either a corrupt zip file somewhere in your path or there is a incompatible version being used. When I did an explore on Maven repository for this library, I found there were newer versions and added the newer version to the pom.xml. I was able to proceed at this point.


Maybe the zip file is damaged, or is brokened when downloading.


I was getting exception

java.util.zip.ZipException: invalid entry CRC (expected 0x0 but got 0xdeadface)
    at java.util.zip.ZipInputStream.read(ZipInputStream.java:221)
    at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:140)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:118)
...

when unzipping an archive in Java. The archive itself didn't seem corrupted as 7zip (and others) opened it without any problems or complaints about invalid CRC.

I switched to Apache Commons Compress for reading the zip-entries and that resolved the problem.


Simply to overcome the ZipException's, i have used a wrapper for commons-compress1.14 called jarchivelibwritten by thrau that makes it easy to extract or compress from and into File objects.

Example:

public static void main(String[] args) {
        String zipfilePath = 
                "E:/Selenium_Server/geckodriver-v0.19.0-linux64.tar.gz";
                //"E:/Selenium_Server/geckodriver-v0.19.0-win32.zip";
        String outdir = "E:/Selenium_Server/";
        exratctFileList(zipfilePath, outdir );
}
public void exratctFileList( String zipfilePath, String outdir ) throws IOException {
    File archive = new File( zipfilePath );
    File destinationDir = new File( outdir );

    Archiver archiver = null;
    if( zipfilePath.endsWith(".zip") ) {
        archiver = ArchiverFactory.createArchiver( ArchiveFormat.ZIP );
    } else if ( zipfilePath.endsWith(".tar.gz") ) {
        archiver = ArchiverFactory.createArchiver( ArchiveFormat.TAR, CompressionType.GZIP );
    }
    archiver.extract(archive, destinationDir);

    ArchiveStream stream = archiver.stream( archive );
    ArchiveEntry entry;

    while( (entry = stream.getNextEntry()) != null ) {
        String entryName = entry.getName();
        System.out.println("Entery Name : "+ entryName );
    }
    stream.close();
}

Maven dependency « You can download the jars from the Sonatype Maven Repository at org/rauschig/jarchivelib/.

<dependency>
  <groupId>org.rauschig</groupId>
  <artifactId>jarchivelib</artifactId>
  <version>0.7.1</version>
</dependency>

@see


On Windows7 I had this problem over a Samba network connection for a Java8 Jar File >80 MBytes big. Copying the file to a local drive fixed the issue.


In my case , my -Dloader.path="lib" contains other jars that doesn't need. for example,mvn dependency:copy-dependencies lists 100 jar files.but my lib directory contains 101 jar files.

참고URL : https://stackoverflow.com/questions/325202/java-util-zip-zipexception-error-in-opening-zip-file

반응형