List of utility methods to do Jar Zip File
void | addFileToJar(File baseDir, File src, JarOutputStream zOut) add File To Jar String name = src.getAbsolutePath(); String prefix = baseDir.getAbsolutePath(); if (prefix.endsWith("/") || prefix.endsWith("\\")) { prefix = prefix.substring(0, prefix.length() - 1); name = name.substring(prefix.length() + 1); name = name.replace('\\', '/'); long timestamp = src.lastModified(); ... |
void | addFileToJar(File file, ZipOutputStream zipStream, String path) add File To Jar FileInputStream fin = new FileInputStream(file); int bufSize = 1024; byte ipBuf[] = new byte[bufSize]; int lenRead = 0; String filename = path + file.getName(); zipStream.putNextEntry(new ZipEntry(filename)); while ((lenRead = fin.read(ipBuf)) > 0) { zipStream.write(ipBuf, 0, lenRead); ... |
void | addFileToJar(File fileOrDirectoryToAdd, File extractedJarPath, JarOutputStream target) add File To Jar String relPath = ""; if (!fileOrDirectoryToAdd.getAbsolutePath().equals(extractedJarPath.getAbsolutePath())) { String fileToAddCanonicalPath = fileOrDirectoryToAdd.getCanonicalPath(); int relStart = extractedJarPath.getCanonicalPath().length() + 1; int relEnd = fileOrDirectoryToAdd.getCanonicalPath().length(); String d = fileToAddCanonicalPath.substring(relStart, relEnd); relPath = d.replace("\\", "/"); BufferedInputStream in = null; try { if (fileOrDirectoryToAdd.isDirectory()) { if (!relPath.isEmpty()) { if (!relPath.endsWith("/")) { relPath += "/"; JarEntry entry = new JarEntry(relPath); entry.setTime(fileOrDirectoryToAdd.lastModified()); target.putNextEntry(entry); target.closeEntry(); for (File nestedFile : fileOrDirectoryToAdd.listFiles()) { addFileToJar(nestedFile, extractedJarPath, target); return; JarEntry entry = new JarEntry(relPath); entry.setTime(fileOrDirectoryToAdd.lastModified()); target.putNextEntry(entry); in = new BufferedInputStream(new FileInputStream(fileOrDirectoryToAdd)); byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) { break; target.write(buffer, 0, count); target.closeEntry(); } finally { if (in != null) { in.close(); |
void | addFileToJar(JarOutputStream jar, InputStream file, String path) Add file to jar with given path byte[] buffer = new byte[8192]; JarEntry entry = new JarEntry(path); jar.putNextEntry(entry); int n; while ((n = file.read(buffer)) > 0) { jar.write(buffer, 0, n); |
void | addJar(File path) Add a file or directory to the classpath. try { Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(classLoader(), new Object[] { path.toURL() }); } catch (Throwable e) { throw new RuntimeException(String.format("Error adding %s to classpath", path), e); |
void | addJarLibralyClassPath(Object classLoaderMakedObject, File jarPath) add Jar Libraly Class Path URLClassLoader classLoader = (URLClassLoader) classLoaderMakedObject.getClass().getClassLoader(); @SuppressWarnings("rawtypes") Class classClassLoader = URLClassLoader.class; Method methodAddUrl = classClassLoader.getDeclaredMethod("addURL", URL.class); methodAddUrl.setAccessible(true); methodAddUrl.invoke(classLoader, jarPath.toURI().toURL()); |
void | addJarLibralySystemClassPath(File jarPath) add Jar Libraly System Class Path URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); @SuppressWarnings("rawtypes") Class classClassLoader = URLClassLoader.class; Method methodAddUrl = classClassLoader.getDeclaredMethod("addURL", URL.class); methodAddUrl.setAccessible(true); methodAddUrl.invoke(classLoader, jarPath.toURI().toURL()); |
void | addJARs(File dir) Add all the jar files in a directory tree to the classpath. if (dir.exists() && dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { if (file.getName().toLowerCase().endsWith(".jar") && !addFile(file)) { System.out.println("Unable to add " + file + " to the classpath."); } else if (file.isDirectory()) ... |
boolean | addJars(File directory, boolean recursive) add Jars return addJars(directory, recursive, null);
|
void | addJarsToClassPath(String jarPath) add Jars To Class Path if (jarPath != null) { File f = new File(jarPath); try { URL u = f.toURI().toURL(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<?> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); ... |