脚本宝典收集整理的这篇文章主要介绍了记一次解决maven项目无法编译的问题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在idea中编译时,出现以下错误
Malformed uxxxx encoding.
经过各种资料和分析后,是因为依赖的jar包有下载不完整导致的。解决办法是,把这些本地maven仓库中下载有问题的jar包删除,重新打包项目即可(idea中就是reload)。
找到并删除这些有问题的jar包的方法,我写了一个java类来操作(依赖commons-io包),具体如下:
package com.tmp; import org.apache.COMmons.io.DirectoryWalker; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.zip.ZiPEntry; import java.util.zip.ZipFile; public class FindInvalidJarAndDel extends DirectoryWalker<String> { public static void main(String[] args) throws IOException { // 查找本地maven仓库 File startDir = new File("C:\Users\beta\.m2\reposITory"); FindInvalidJarAndDel finder = new FindInvalidJarAndDel(); List<String> finded = new ArrayList<>(); finder.walk(startDir, finded); if (finded.size() > 0) { //删除对应的文件 for (String f : finded) { System.out.PRintln(f); try { FileUtils.forceDelete(new File(f));//删除整个文件夹 } catch (IOException e) { e.printStackTrace(); } } } } protected void handleFile(File file, int depth, Collection<String> results) throws IOException { if (results.contains(file.getParent())) { return; } if (file.getName().endsWith(".lastUpdated")||file.getName().toLowerCase().endsWith("resolver-status.properties")) { results.add(file.getParent()); return; } if (file.getName().endsWith(".jar")) { //尝试解压一下,如果不能解压,则说明jar包有问题 try { ZipFile zip = new ZipFile(file); Enumeration zipEntries = zip.entries(); while (zipEntries.hasMoreElements()) { ZipEntry entry = (ZipEntry) zipEntries.nextElement(); entry.getName(); entry.getSize(); } } catch (Exception e) { results.add(file.getParent()); return; } } } }
以上是脚本宝典为你收集整理的记一次解决maven项目无法编译的问题全部内容,希望文章能够帮你解决记一次解决maven项目无法编译的问题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。