有時候maven真的很坑! 有時候提示invalid LOC header (bad signat signature), 但又有時候什麼都不提示,工程報錯,情況有肯多中,不知道大家遇到過幾種詭異的. ...
有時候maven真的很坑!
有時候提示invalid LOC header (bad signat signature),
但又有時候什麼都不提示,工程報錯,情況有肯多中,不知道大家遇到過幾種詭異的.
很多人說加-U參數或在maven插件選擇強制刷新等操作,但很不好使,一點用都沒有.
今天我就遇到POM提示第一行錯誤,這怎麼可能?其他任何地方都不報錯,用mvn命令的時候才能看到jar invalid.
我還遇到整個spring的項目只有test報錯,其他的都不報錯,編輯器里提示的Unknown Error~
真沒法玩了~我知道肯定有一個或幾個jar下載的有問題.但就算你知道了難道一個一個去找刪?一個還好說,有時候5,6個真是浪費時間.
不如就寫個代碼跑一下吧~
public class MvnCheckJar { public static void main(String[] args) throws Exception { String localMvnPath = "F:/mvnlib"; // 遍歷文件夾,找出jar\pom和效驗文件進行對比,如果不相符,則刪除 getFile(new File(localMvnPath), "jar,pom"); System.out.println("完畢"); } public static void getFile(File path, String suffixs) throws Exception { String[] suffixs_ = new String[] {}; if (suffixs != null) suffixs_ = suffixs.split(","); if (path.isFile()) { for (String suffix : suffixs_) { if (path.getName().endsWith(suffix)) { // System.out.println(path.getAbsolutePath() ); handler(path); } } } else { File[] ff = path.listFiles(); if(ff!=null) for (File x : ff) { getFile(x, suffixs); } } } /** * 驗證,發現不匹配則刪除 * * @throws IOException */ public static void handler(File f) throws Exception { File fsha1 = new File(f.getAbsolutePath() + ".sha1"); if (fsha1.exists()) { String sha1 = FileUtils.readFileToString(fsha1, "utf-8").replaceAll("(?m).*(\\w{40}).*", "$1").replaceAll("\\n|\\r", ""); String currsha1 = sha1(f); if(!sha1.equals(currsha1)){//如果不等,則刪除 當前文件和sha1 // System.out.println("sha1file: " + sha1 ); fsha1.delete(); f.delete(); System.out.println(sha1 + " , " + currsha1 + " , " + f.getAbsolutePath()); } } else { f.delete(); } } public static String sha1(File f) throws Exception { try (FileInputStream fis = new FileInputStream(f)) { return org.apache.commons.codec.digest.DigestUtils.sha1Hex(fis); } } }