RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何解压jar

这篇文章给大家介绍如何解压jar,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都网站建设公司更懂你!创新互联建站只做搜索引擎喜欢的网站!成都网站制作前台采用搜索引擎认可的DIV+CSS架构,全站HTML静态,H5页面制作+CSS3网站,提供:网站建设,微信开发,小程序开发,成都做商城网站成都App定制开发,国际域名空间,服务器租售,网站代托管运营,微信公众号代托管运营。

场景

  • 页面上传jar包

  • 后台解压jar包

  • 页面展示所有package

  • 选择一个package

  • 页面显示class和子package

    • 选择class,进入class解析页面

    • 选择package,显示class和子package

解压jar

package com.wuxiongwei.java.jar2;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
 * 非常好的工具类 
 * 解压jar.  * @author  * @version 1.0.0  */ public class JarDecompression {     protected static Log log = LogFactory.getLog(JarDecompression.class);     @SuppressWarnings("resource")     public static void uncompress(File jarFile, File tarDir) throws IOException {         JarFile jfInst = new JarFile(jarFile);         Enumeration enumEntry = jfInst.entries();         while (enumEntry.hasMoreElements()) {             JarEntry jarEntry = (JarEntry) enumEntry.nextElement();             File tarFile = new File(tarDir, jarEntry.getName());             if(jarEntry.getName().contains("META-INF")){                 File miFile = new File(tarDir, "META-INF");                 if(!miFile.exists()){                     miFile.mkdirs();                 }             }             makeFile(jarEntry, tarFile);             if (jarEntry.isDirectory()) {                 continue;             }             FileChannel fileChannel = new FileOutputStream(tarFile).getChannel();             InputStream ins = jfInst.getInputStream(jarEntry);             transferStream(ins, fileChannel);         }     }     /**      * 流交换操作      * @param ins 输入流      * @param channel 输出流      */     private static void transferStream(InputStream ins, FileChannel channel) {         ByteBuffer byteBuffer = ByteBuffer.allocate(1024 * 10);         ReadableByteChannel rbcInst = Channels.newChannel(ins);         try {             while (-1 != (rbcInst.read(byteBuffer))) {                 byteBuffer.flip();                 channel.write(byteBuffer);                 byteBuffer.clear();             }         } catch (IOException ioe) {             ioe.printStackTrace();         } finally {             if (null != rbcInst) {                 try {                     rbcInst.close();                 } catch (IOException e) {                     e.printStackTrace();                 }             }             if (null != channel) {                 try {                     channel.close();                 } catch (IOException e) {                     e.printStackTrace();                 }             }         }     }     /**      * 打印jar文件内容信息      * @param file jar文件      */     public static void printJarEntry(File file) {         JarFile jfInst = null;;         try {             jfInst = new JarFile(file);         } catch (IOException e) {             e.printStackTrace();         }         Enumeration enumEntry = jfInst.entries();         while (enumEntry.hasMoreElements()) {             log.info((enumEntry.nextElement()));         }     }     /**      * 创建文件      * @param jarEntry jar实体      * @param fileInst 文件实体      * @throws IOException 抛出异常      */     public static void makeFile(JarEntry jarEntry, File fileInst) {         if (!fileInst.exists()) {             if (jarEntry.isDirectory()) {                 fileInst.mkdirs();             } else {                 try {                     fileInst.createNewFile();                 } catch (IOException e) {                     log.error("创建文件失败>>>".concat(fileInst.getPath()));                 }             }         }     }     public static void main(String[] args) {         File jarFile = new File("/Users/mac/Documents/other/bw2/bopsdk-openapi-1.0.2-Release.jar");         File targetDir = new File("/Users/mac/Documents/other/bw2/test/");         try {             JarDecompression.uncompress(jarFile, targetDir);         } catch (IOException e) {             e.printStackTrace();         }     } }

关于如何解压jar就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


分享题目:如何解压jar
文章地址:http://scyingshan.cn/article/pgjgid.html