在一次啟動tomcat的過程中報錯:
java.lang.IllegalArgumentException: Malformed
這個與前面在其他網站上看到的是不同的:java.lang.IllegalArgumentException: Malformed 一般會帶有encoding XXX 或者 \u xxxx
但是我看到的錯誤就只有這個
如何定位:
【1】修改tomcat catanila.jar 中的ContextConfig的源代碼:
protected void processAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly) { Jar jar = null; InputStream is; try { // String t = url.getPath().substring(6); // t = t.substring(0,t.length()-2); // ZipFile zf = new ZipFile(t, "utf-8"); // Enumeration e = zf.getEntries(); // while(e.hasMoreElements()) // { // System.out.println(e.nextElement()); // } // zf.closeQuietly(zf); jar = JarFactory.newInstance(url); log.info("current jar file is:" + jar.getEntryName() + " jar:" + url.getPath()); jar.nextEntry(); String entryName = jar.getEntryName(); while (entryName != null) { if (entryName.endsWith(".class")) { is = null; try { is = jar.getEntryInputStream(); processAnnotationsStream( is, fragment, handlesTypesOnly); } catch (IOException e) { log.error(sm.getString("contextConfig.inputStreamJar", entryName, url),e); } catch (ClassFormatException e) { log.error(sm.getString("contextConfig.inputStreamJar", entryName, url),e); } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { // Ignore } } } } jar.nextEntry(); entryName = jar.getEntryName(); } } catch (IOException e) { log.error(sm.getString("contextConfig.jarFile", url), e); } finally { if (jar != null) { jar.close(); } } }這里可以看到只捕獲了IOException,為了定位該問題 在catch 部分,修改如下:
protected void processAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly) { Jar jar = null; InputStream is; String entryName = null; try { jar = JarFactory.newInstance(url); log.info("current jar file is:" + jar.getEntryName() + " jar:" + url.getPath()); jar.nextEntry(); entryName = jar.getEntryName(); while (entryName != null) { if (entryName.endsWith(".class")) { is = null; try { is = jar.getEntryInputStream(); processAnnotationsStream( is, fragment, handlesTypesOnly); } catch (IOException e) { log.error(sm.getString("contextConfig.inputStreamJar", entryName, url),e); } catch (ClassFormatException e) { log.error(sm.getString("contextConfig.inputStreamJar", entryName, url),e); } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { // Ignore } } } } jar.nextEntry(); entryName = jar.getEntryName(); } } catch (Exception e) { log.warn("current jar:" + url.getPath() + " class:" + entryName); log.error(sm.getString("contextConfig.jarFile", url), e); } finally { if (jar != null) { jar.close(); } } }
最后問題得原因一般是:jar包打入了包含中文的文件名
如果可以直接調試的話還可以參考tomcat的啟動調試:http://blog.csdn.net/scugxl/article/details/37083497