jar包内所有的文件都属于class,需要采用非正常方法加载,参考的是 Jinteltype的源码
void fromJarToFs(String jarPath, String filePath) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
File file = new File(filePath);
if (file.exists()) {
boolean success = file.delete();
if (!success) {
throw new IOException("Could not delete file: " + filePath);
}
}
is = ClassLoader.getSystemClassLoader().getResourceAsStream(jarPath);
os = new FileOutputStream(filePath);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception ex) {
throw new IOException("FromJarToFileSystem failed " + jarPath, ex);
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}