集册 Java实例教程 使用URL获取Jar文件

使用URL获取Jar文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

779
使用URL获取Jar文件

import java.io.IOException;

import java.net.JarURLConnection;

import java.net.MalformedURLException;

import java.net.URL;
/**
N o w J a v a . c o m - 时  代  Java
**/

import java.util.jar.JarEntry;

import java.util.jar.JarFile;


public class Main {

  public static void main(String[] args) {

    try {

      URL url = new URL("jar:http://hostname/my.jar!/");


      url = new URL("jar:file:/c:/folder/my.jar!/");


      // Get the jar file

      JarURLConnection conn = (JarURLConnection) url.openConnection();

      JarFile jarfile = conn.getJarFile();


      String entryName = conn.getEntryName(); // null


      url = new URL("jar:file:/c:/folder/my.jar!/com/mycompany/MyClass.class");//来自 时 代 J a v a 公 众 号 - nowjava.com


      // Get the jar file

      conn = (JarURLConnection) url.openConnection();

      jarfile = conn.getJarFile();


      // Get the entry name; it should be the same as specified on URL

      en
展开阅读全文