开发者

extract jar content and stored in destination folder

how i can extract all folder ,sub-folders, all file and files and folder inside sub-folder that are stored inside any jar file and opy those content int开发者_JS百科o destination folder in java an while coding in eclipse platform......... can anybody suggest me... i tried many code related to zipinput stream.. storing in zipfile entities in enumeretion and writing it to detination folder. but none of it works properly......


Invoke

jar xf yourApp.jar

from java and it will do.

See Also

  • Using JAR Files: The Basics


I've written a helper class to do that:

http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/util/zip/ZipFiles.html

You can read in my blog more about the latest release and how to get it:

http://puces-blog.blogspot.com/2011/03/news-from-software-smithy.html


If you want an Eclipse based solution, select

File menu > Import ... > General > Archive File

But if you want a Java code solution, here's one using Guava:

public static void unpackZipFile(final File archive, final File targetDirectory)
throws ZipException, IOException {
    ZipFile zipFile = new ZipFile(archive);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry zipEntry = entries.nextElement();
        if (zipEntry.isDirectory())
            continue;
        final File targetFile = new File(targetDirectory,
            zipEntry.getName());
        Files.createParentDirs(targetFile);
        ByteStreams.copy(zipFile.getInputStream(zipEntry), Files
            .newOutputStreamSupplier(targetFile).getOutput());
    }
}


You can use this very simple library to pack/unpack jar file

JarManager

Very simple

import java.io.File;
import java.util.List;

import fr.stevecohen.jarmanager.JarUnpacker;

class Test {
   JarUnpacker jarUnpacker = new JarUnpacker(); 
   File myfile = new File("./myfile.jar");
   File unpackDir = new File("./mydir");

   List<File> unpacked_files = jarUnpacker.unpack(myfile.getAbsolutePath(), unpackDir.getAbsolutePath());
}

You can also use maven dependency

<dependency>
    <groupId>fr.stevecohen.jarmanager</groupId>
    <artifactId>JarManager</artifactId>
    <version>0.5.0</version>
</dependency>

You also need my repository

<repository>
    <id>repo-reapersoon</id>
    <name>ReaperSoon's repo</name>
    <url>http://repo-maven.stevecohen.fr</url>
</repository>

Check the last version with the link bellow to use the last dependency

Please use my public issue tracker if you find some bugs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜