invalid LOC header 与 Could not publish to the server. java.lang.IndexOutOfBoundsException 错误处理

1. 项目eclipse 部署问题
Could not publish to the server. java.lang.IndexOutOfBoundsException
原因: pom.xml 依赖的jar包有错误,maven 下载jar时,文件为下载文章

由于jar 包文件众多, 写了一个小工具进行循环排除,哪一个文件错误
之后进行 update maven project 操作,
注意: 如果jar 还是下载不全, 只能自行到官网进行下载,放置本地仓库

2. invalid LOC header   也是同样原因

查找错误文件工具类

package com.tools;


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
//注意要将文件保存为utf-8,txt文件的默认保存为ANSI.要改成urf-8不然会像file:ziptestfile/fileInZip.txt
public class ReadZip {


    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        ReadZip rz=new ReadZip();
        File file = new File("C:\\Users\\Administrator\\.m2\\repository");
        List<File> list = new ArrayList<File>();
        rz.getJarFile(file, list);
        for(File temp: list) {
        rz.readZipContext(temp.getAbsolutePath());
        }
    }
    
    public void getJarFile(File file, List<File> list) {
    if(file.isDirectory()) {
    for(File temp: file.listFiles()) {
    getJarFile(temp, list);
        }
    } else if(file.getName().endsWith("jar")){
    list.add(file);
    }
    }
    
    public void readZipContext(String zipPath) throws IOException{
    ZipFile zf = null;
    try {
    zf=new ZipFile(zipPath);
    } catch (ZipException e) {
            System.out.println(zipPath);
            return ;
        }


        InputStream in=new BufferedInputStream(new FileInputStream(zipPath));
        ZipInputStream zin=new ZipInputStream(in);
        //ZipEntry 类用于表示 ZIP 文件条目。
        ZipEntry ze;
        while((ze=zin.getNextEntry())!=null){
            if(ze.isDirectory()){
                //为空的文件夹什么都不做
            }else{
                    BufferedReader reader;
                    try {
                    zf.getInputStream(ze).read(new byte[1000], 0, 1000);
//                        reader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze), "utf-8"));
//                        reader.close();
                    } catch (IOException e) {
                    zin.close();
                    in.close();
                    zf.close();
                    System.out.println(zipPath);
                    File file = new File(zipPath);
                    File fileParent = file.getParentFile();
                    File[] childrenFiles = fileParent.listFiles();
                    for(File temp : childrenFiles) {
                     
                    if( temp.delete()) {
                        System.out.println("delete:" + temp.getAbsolutePath());
                        }
                     
                    }
                     
                        // TODO Auto-generated catch block
                       break;
                    }


            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xuezhezhishen/article/details/80926833
今日推荐