當前位置: 首頁>>代碼示例>>Java>>正文


Java JarURLConnection.getJarFile方法代碼示例

本文整理匯總了Java中java.net.JarURLConnection.getJarFile方法的典型用法代碼示例。如果您正苦於以下問題:Java JarURLConnection.getJarFile方法的具體用法?Java JarURLConnection.getJarFile怎麽用?Java JarURLConnection.getJarFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.JarURLConnection的用法示例。


在下文中一共展示了JarURLConnection.getJarFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: jarCreateTemplate

import java.net.JarURLConnection; //導入方法依賴的package包/類
/**
 * 將jar裏麵的文件複製到模板文件夾
 * 
 * @param jarConn
 * @return
 * @throws IOException
 */
public static void jarCreateTemplate(JarURLConnection jarConn) throws IOException {
	try (JarFile jarFile = jarConn.getJarFile()) {
		Enumeration<JarEntry> entrys = jarFile.entries();
		while (entrys.hasMoreElements()) {
			JarEntry entry = entrys.nextElement();
			if (entry.getName().startsWith(jarConn.getEntryName()) && !entry.getName().endsWith("/")) {
				String fileName = entry.getName().replace(TEMPLATE_DIR + "/", "");
				InputStream inpt = Thread.currentThread().getContextClassLoader()
						.getResourceAsStream(entry.getName());
				Files.copy(inpt, Paths.get(TEMPLATE_DIR, fileName));
			}
		}
	}

}
 
開發者ID:shenzhenMirren,項目名稱:vertx-generator,代碼行數:23,代碼來源:TemplateUtil.java

示例2: loadClassFromJarFile

import java.net.JarURLConnection; //導入方法依賴的package包/類
private static List<Class<?>> loadClassFromJarFile(URL url) {
    List<Class<?>> list = new LinkedList<>();
    try {
        JarURLConnection connection = (JarURLConnection) url.openConnection();
        JarFile jarFile = connection.getJarFile();
        Enumeration<JarEntry> jarEntries = jarFile.entries();
        while (jarEntries.hasMoreElements()) {
            String entryName = jarEntries.nextElement().getName();
            if (entryName.endsWith(".class")) {
                list.add(loadClass(entryName.substring(0, entryName.length() - 6).replace("/", ".")));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return list;
}
 
開發者ID:omsfuk,項目名稱:Samurai,代碼行數:18,代碼來源:ClassUtil.java

示例3: checkJarFile

import java.net.JarURLConnection; //導入方法依賴的package包/類
private void checkJarFile(final ClassLoader classLoader, final URL url, final String pckgname) throws IOException {
    final JarURLConnection conn = (JarURLConnection) url.openConnection();
    final JarFile jarFile = conn.getJarFile();
    final Enumeration<JarEntry> entries = jarFile.entries();

    while (entries.hasMoreElements()) {
        final JarEntry jarEntry = entries.nextElement();

        String name = jarEntry.getName();

        if (name.endsWith(".class")) {
            name = name.substring(0, name.length() - 6).replace('/', '.');

            if (name.startsWith(pckgname)) {
                addClass(classLoader, name);
            }
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:20,代碼來源:ClassPathScanner.java

示例4: getVersion

import java.net.JarURLConnection; //導入方法依賴的package包/類
private static String getVersion()
{
	try
	{
		String path = VDMJC.class.getName().replaceAll("\\.", "/");
		URL url = VDMJC.class.getResource("/" + path + ".class");
		JarURLConnection conn = (JarURLConnection)url.openConnection();
	    JarFile jar = conn.getJarFile();
		Manifest mf = jar.getManifest();
		String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
		return version;
	}
	catch (Exception e)
	{
		return null;
	}
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:18,代碼來源:VDMJC.java

示例5: getVersion

import java.net.JarURLConnection; //導入方法依賴的package包/類
private static String getVersion()
{
	try
	{
		String path = VDMJ.class.getName().replaceAll("\\.", "/");
		URL url = VDMJ.class.getResource("/" + path + ".class");
		JarURLConnection conn = (JarURLConnection)url.openConnection();
	    JarFile jar = conn.getJarFile();
		Manifest mf = jar.getManifest();
		String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
		return version;
	}
	catch (Exception e)
	{
		return null;
	}
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:18,代碼來源:VDMJ.java

示例6: recursivelyCopyContent

import java.net.JarURLConnection; //導入方法依賴的package包/類
/**
 * Unpacks desired folder structure from the JAR file into temporal location and returns that location absolute path
 * as string.
 *
 * @param connection
 *            connection to the JAR file
 * @param rootName
 *            name of the folder to be unpacked
 * @return absolute path to the temporarily unpacked folder
 * @throws IOException
 *             for IO operations
 */
protected static String recursivelyCopyContent(JarURLConnection connection, String rootName) throws IOException {
	final File tempFolder = getTempFolder();
	tempFolder.deleteOnExit();
	final File rootFolder = new File(tempFolder, rootName);
	if (rootFolder.exists()) {
		FileDeleter.delete(rootFolder.toPath());
	}
	checkState(rootFolder.mkdir(), "Error while creating folder for Node.js environment. " + rootFolder);
	checkState(rootFolder.isDirectory(), "Expected directory but got a file: " + rootFolder);
	rootFolder.deleteOnExit();

	try (final JarFile jarFile = connection.getJarFile()) {
		for (final Enumeration<JarEntry> em = jarFile.entries(); em.hasMoreElements(); /**/) {
			final JarEntry entry = em.nextElement();
			// Do not process anything which is not under desired root
			if (!entry.getName().startsWith(rootName)) {
				continue;
			}
			final String fileName = entry.getName();// .substring(connection.getEntryName().length());
			final File newResource = new File(tempFolder, fileName);
			if (entry.isDirectory()) {
				if (!newResource.exists()) {
					checkState(newResource.mkdir(), "Error while creating new folder at: " + newResource);
				}
			} else {
				checkState(newResource.createNewFile(), "Error while creating new file at: " + newResource);
				try (final InputStream is = jarFile.getInputStream(entry)) {
					com.google.common.io.Files.copy(() -> is, newResource);
				}
			}
			newResource.deleteOnExit();
		}
	}
	return rootFolder.getCanonicalFile().getAbsolutePath().replace("\\", "\\\\");
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:48,代碼來源:ShippedCodeAccess.java

示例7: addResourcesJar

import java.net.JarURLConnection; //導入方法依賴的package包/類
/**
 * Add a resources JAR. The contents of /META-INF/resources/ will be used if
 * a requested resource can not be found in the main context.
 */
public void addResourcesJar(URL url) {
    try {
        JarURLConnection conn = (JarURLConnection) url.openConnection();
        JarFile jarFile = conn.getJarFile();   
        ZipEntry entry = jarFile.getEntry("/");
        WARDirContext warDirContext = new WARDirContext(jarFile,
                new WARDirContext.Entry("/", entry));
        warDirContext.loadEntries();
        altDirContexts.add(warDirContext);
    } catch (IOException ioe) {
        log.warn(sm.getString("resources.addResourcesJarFail", url), ioe);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:18,代碼來源:BaseDirContext.java

示例8: getJarFile

import java.net.JarURLConnection; //導入方法依賴的package包/類
@Override
public JarFile getJarFile() throws IOException {
    URL jarFileUrl = new URL("jar:" + jarUrl + "!/");
    JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
    conn.setUseCaches(false);
    conn.connect();
    return conn.getJarFile();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:9,代碼來源:JarURLResource.java

示例9: copyJarResourcesRecursively

import java.net.JarURLConnection; //導入方法依賴的package包/類
public static boolean copyJarResourcesRecursively(
        final File destDir, final JarURLConnection jarConnection
) throws IOException {

    final JarFile jarFile = jarConnection.getJarFile();

    for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
        final JarEntry entry = e.nextElement();
        if (entry.getName().startsWith(jarConnection.getEntryName())) {
            final String filename = StringUtils.removeStart(
                    entry.getName(), //
                    jarConnection.getEntryName());

            final File f = new File(destDir, filename);
            if (!entry.isDirectory()) {
                final InputStream entryInputStream = jarFile.getInputStream(entry);
                if (!FileUtils.copyStream(entryInputStream, f)) {
                    return false;
                }
                entryInputStream.close();
            } else {
                if (!FileUtils.ensureDirectoryExists(f)) {
                    throw new IOException("Could not create directory: " + f.getAbsolutePath());
                }
            }
        }
    }
    return true;
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:30,代碼來源:FileUtils.java

示例10: getJarVersion

import java.net.JarURLConnection; //導入方法依賴的package包/類
private String getJarVersion(final String jarUrl) {
	String version = null;
	try {
		final URL url = new URL("jar:" + jarUrl + "!/");
		final JarURLConnection juc = (JarURLConnection) url
				.openConnection();
		final JarFile jf = juc.getJarFile();
		final Attributes attrs = jf.getManifest().getMainAttributes();
		version = attrs.getValue("Manifest-Version");
	} catch (final IOException e) {
		e.printStackTrace();
	}
	return version;
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:15,代碼來源:JarFileLoaderService.java

示例11: getJarFile

import java.net.JarURLConnection; //導入方法依賴的package包/類
private JarFile getJarFile(URL jarFileUrl) throws IOException {
    JarFile jarFile = null;

    if (jarFileUrl != null) {
        JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
        conn.setUseCaches(false);
        conn.connect();
        jarFile = conn.getJarFile();
    }

    return jarFile;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:ParserController.java

示例12: getClasses

import java.net.JarURLConnection; //導入方法依賴的package包/類
/**
 * 獲取指定包下所有類
 *
 * @param packageName
 * @return
 */
public static ArrayList<Class<?>> getClasses(String packageName) {
    ArrayList<Class<?>> classes = new ArrayList<>();
    try {
        Enumeration<URL> urls = getClassLoader().getResources(packageName.replace(".", "/"));
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            if (url != null) {
                String protocol = url.getProtocol();
                if (protocol.equals("file")) {
                    String packagePath = url.getPath().replaceAll("%20", " ");
                    addClass(classes, packagePath, packageName);
                } else if (protocol.equals("jar")) {
                    JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
                    if (jarURLConnection != null) {
                        JarFile jarFile = jarURLConnection.getJarFile();
                        if (jarFile != null) {
                            Enumeration<JarEntry> jarEntries = jarFile.entries();
                            while (jarEntries.hasMoreElements()) {
                                JarEntry jarEntry = jarEntries.nextElement();
                                String jarEntryName = jarEntry.getName();
                                if (jarEntryName.equals(".class")) {
                                    String className = jarEntryName.substring(0, jarEntryName.lastIndexOf(".")).replaceAll("/", ".");
                                    doAddClass(classes, className);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
       e.printStackTrace();
        throw new RuntimeException(e);
    }
    return classes;
}
 
開發者ID:CFshuming,項目名稱:bfmvc,代碼行數:43,代碼來源:ClassUtil.java

示例13: getBeanClassListIterate

import java.net.JarURLConnection; //導入方法依賴的package包/類
public List<Class<?>> getBeanClassListIterate(String packageName) {
  	
  	List<Class<?>> classList = new ArrayList<Class<?>>();
  	Enumeration<URL> urls = null;
  	
  	try {
	urls = ClassUtil.getClassLoader().getResources(packageName.replace(".", "/"));
} catch (IOException e1) {
	e1.printStackTrace();
}
  	
      // 遍曆 URL 資源
      while (urls.hasMoreElements()) {
          URL url = urls.nextElement();
          if (url != null) {
              // 獲取協議名(分為 file 與 jar)
              String protocol = url.getProtocol();
              if (protocol.equals("file")) {
                  // 若在 class 目錄中,則執行添加類操作
                  String packagePath = url.getPath();
                  addClass(classList, packagePath, packageName);
              } else if (protocol.equals("jar")) {

			try {
                   // 若在 jar 包中,則解析 jar 包中的 entry
                   JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
                   JarFile jarFile = jarURLConnection.getJarFile();
				
                   Enumeration<JarEntry> jarEntries = jarFile.entries();
                   while (jarEntries.hasMoreElements()) {
                       JarEntry jarEntry = jarEntries.nextElement();
                       String jarEntryName = jarEntry.getName();
                       // 判斷該 entry 是否為 class
                       if (jarEntryName.endsWith(".class")) {
                           // 獲取類名
                           String className = jarEntryName.substring(0, jarEntryName.lastIndexOf(".")).replaceAll("/", ".");
                           // 執行添加類操作
                           doAddClass(classList, className);
                       }
                   }						
				
			} catch (IOException e) {
				e.printStackTrace();
			}

              }
          }
      }    	
  	
      return classList;
      
  }
 
開發者ID:smxc,項目名稱:garlicts,代碼行數:53,代碼來源:BeanLoaderTemplate.java

示例14: FileUrlJar

import java.net.JarURLConnection; //導入方法依賴的package包/類
public FileUrlJar(URL url) throws IOException {
    JarURLConnection jarConn = (JarURLConnection) url.openConnection();
    jarConn.setUseCaches(false);
    jarFile = jarConn.getJarFile();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:6,代碼來源:FileUrlJar.java

示例15: getClassSet

import java.net.JarURLConnection; //導入方法依賴的package包/類
/**
 * 獲取類集合
 * 
 * @param packageName 掃描路徑
 * @return Set
 */
public static Set<Class<?>> getClassSet(String packageName) {
    try {
        Set<Class<?>> classSet = new HashSet<>();
        Enumeration<URL> urls = getClassLoader().getResources(packageName.replace(".", "/"));
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            if (Objects.isNull(url)) {
                continue;
            }
            // 獲取此 URL 的協議名稱。
            String protocol = url.getProtocol();
            if ("file".equals(protocol)) {
                // %20 表示file協議?
                String packagePath = url.getPath().replaceAll("%20", " ");
                addClass(classSet, packagePath, packageName);
            } else if ("jar".equals(protocol)) {
                JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
                if (Objects.isNull(jarURLConnection)) {
                    continue;
                }
                JarFile jarFile = jarURLConnection.getJarFile();
                if (Objects.isNull(jarFile)) {
                    continue;
                }
                Enumeration<JarEntry> jarEntries = jarFile.entries();
                while (jarEntries.hasMoreElements()) {
                    JarEntry jarEntry = jarEntries.nextElement();
                    String jarEntryName = jarEntry.getName();
                    if (jarEntryName.endsWith(".class")) {
                        String className = jarEntryName.substring(0, jarEntryName.lastIndexOf(".")).replaceAll("/",
                                ".");
                        doAddClass(classSet, className);
                    }
                }
            }
        }
        return classSet;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:liaochong,項目名稱:spring-boot-starter-converter,代碼行數:48,代碼來源:ClassUtil.java


注:本文中的java.net.JarURLConnection.getJarFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。