Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compress jar

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to compress jar, the content is concise and easy to understand, can definitely make your eyes bright, through the detailed introduction of this article, I hope you can get something.

Scene

Upload the jar package on the page

Extract the jar package in the background

The page shows all the package

Select a package

The page displays class and sub-package

Select class to go to the class parsing page

Select package to display class and sub-package

Compressed into jarpackage com.wuxiongwei.java.jar2;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.zip.CRC32;import java.util.zip.CheckedOutputStream;import java.util.zip.ZipEntry;import java.util.zip.ZipOutputStream;/** * a very good utility class

* compressed into jar. * @ author * @ version 1.0.0 * / public class JarCompressor {private static Log log = LogFactory.getLog (JarCompressor.class); private static final int BUFFER = 8192; private File fileName; private String originalUrl; public JarCompressor (String pathName) {fileName = new File (pathName);} public void compress (String...) PathName) {ZipOutputStream out = null; try {FileOutputStream fileOutputStream = new FileOutputStream (fileName); CheckedOutputStream cos = new CheckedOutputStream (fileOutputStream, new CRC32 ()); out = new ZipOutputStream (cos); String basedir = ""; for (int I = 0; I < pathName.length) Compress +) {compress (new File (pathname [I]), out, basedir);} out.close ();} catch (Exception e) {throw new RuntimeException (e);}} public void compress (String srcPathName) {File file = new File (srcPathName) If (! file.exists ()) throw new RuntimeException (srcPathName + "does not exist!") ; try {FileOutputStream fileOutputStream = new FileOutputStream (fileName); CheckedOutputStream cos = new CheckedOutputStream (fileOutputStream, new CRC32 ()); ZipOutputStream out = new ZipOutputStream (cos); String basedir = ""; compress (file, out, basedir); out.close ();} catch (Exception e) {throw new RuntimeException (e) }} private void compress (File file, ZipOutputStream out, String basedir) {/ * determine whether it is a directory or a file * / if (file.isDirectory ()) {this.compressDirectory (file, out, basedir);} else {this.compressFile (file, out, basedir) } / * compressed directory * @ param dir * @ param out * @ param basedir * / private void compressDirectory (File dir, ZipOutputStream out, String basedir) {if (! dir.exists ()) return; File [] files = dir.listFiles (); for (int I = 0; I < files.length ) {/ * Recursive * / compress (files [I], out, basedir + dir.getName () + "/") }} / * compressed file * @ param file * @ param out * @ param basedir * / private void compressFile (File file, ZipOutputStream out, String basedir) {if (! file.exists ()) {return;} try {BufferedInputStream bis = new BufferedInputStream (new FileInputStream (file)) String filePath = (basedir + file.getName ()) .replaceAll (getOriginalUrl () + "/", "); log.info (" compressed file: "+ filePath); ZipEntry entry = new ZipEntry (filePath); out.putNextEntry (entry); int count; byte data [] = new byte [BUFFER] While ((count = bis.read (data, 0, BUFFER))! =-1) {out.write (data, 0, count);} bis.close ();} catch (Exception e) {throw new RuntimeException (e) } public static void main (String [] args) {JarCompressor zc = new JarCompressor ("/ Users/mac/Documents/other/bw2/test.jar"); zc.compress ("/ Users/mac/Documents/other/bw2/test/");} public String getOriginalUrl () {return originalUrl;} public void setOriginalUrl (String originalUrl) {this.originalUrl = originalUrl }} the above is how to compress jar. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report