当前位置: 首页>>代码示例>>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;未经允许,请勿转载。