Extract nested Jar File

Okay, I've been looking all day for solutions to this problem and nothing I've found pinpointed the solution, so if anyone would rather point me to another site, that's great.
I have a .jar installer ( installer.jar ) that contains the installer code and a nested jar file ( program.jar ).
In my experience, plain text files work great in the "getInputStream() -> FileWriter.write()" method, but my way of handling images requires javax.imageio.ImageIO, and i'm hoping something similar exists for jars.
ALL+* i want to do is extract that jar file into the current directory, but the ZipEntry.getInputStream() method didn't work, and JarInputStream just confuses me.
If anyone has links to other topics or source code to point to how a jarfile can be extracted.

Thanks for the help.
After looking around and finally noticing the Pack200 package, I have the answer!
JarFile jf = new JarFile( "outside.jar" );
JarOutputStream jos = new JarOutputStream( new FileOutputStream( new File( "inside.jar" ) ) );
Pack200.newUnpacker().unpack( jar.getInputStream( jar.getEntry( "inside.jar" ) ), jos );
jos.close();This creates a JarOutputStream that will write to the FileOutputStream forever until closed.
The Pack200 Unpacker takes the inputstream and outputs it to the JarOutputStream.
When the unpack method returns, the jar file is ready. Close the jar output stream and you have a workable jar!

Similar Messages

  • Easy way to extract a jar file?

    I'm looking for an easy way to extract a jar file from with in a java program. I would also like to specify what directory it goes into. I can't seem to find anything on this.

    >
    ...I can't seem to find anything on this.>Where were you looking, under the bed and in the closet? Try [search: extract jar Java|http://lmgtfy.com/?q=extract+jar+Java].
    As to specifying a directory, offer the end user a JFileChooser set to browse directories only.

  • How to extract ZIP/JAR files?

    Hello,
    How can I extract zip/jar files ?
    Eric

    If you are talking java, you can use the java.util.zip classes.
    ZipFile, ZipEntry, ZipInputStream, ZipOutputStream
    You can find lots of examples through google:
    http://www.google.com/search?hl=en&q=java+zip+code+example&meta=Cheers,
    evnafets

  • Reading nested jar files

    How to read and display contents of nested jar files
    Let the jar format is something like this.
    Parent.jar
                child11.png
                child12.xml
                child13.jar
                            child21.png
                            child22.xml
                            child23.jar
                 -

    You need to play around with classloaders to do it, and unless you know how to do this, there's little point someone giving you the code to, since you won't be able to debug it

  • Nested jar files

    two questions:
    1) How can I get access to a nested jar file? That is lets say i have a jar file names "Outer.jar", which includes two jar files. These two inner jar files each have a main method. Example: "Inner1.jar" and "Inner2.jar". How can I run each inner jar file? Is this possible?
    That is: "Inner1.jar" works perfectly fine by itself, if it was the only jar file, and it has it's own main method. The same goes for "Inner2.jar". But, How can I put these two into a main jar file, "Outer.jar", and then run each of the two inner jar files?
    2) Is it possible to make a jar file that contains two jar files both of which have separate main methods?

    It makes a great deal of sense to nest jar files. For example, I'm trying to put together a standalone JavaHelp "document". Wouldn't it be great if my customer could double click on a jar file and have a JavaHelp view open up with the documents inside? This requires bundling a JavaHelp jar, a viewer jar, and the document jar containing the docs and helpset. The only thing the customer needs in a JRE. No fuss, no muss, no messy installation.
    Another situation is where I want to bundle up multiple jar files as one to simplify distribution and deployment.
    --jon
    I've never heard of anyone wanting to do this before
    but:
    1. I think the only way to do this will be to use a
    custom classloader. You could have a runnable class in
    your Outer.jar that launches a custom classloader.
    This custom classloader will load your classes and you
    can call your runnable classes in Inner1.jar and
    Inner2.jar using seperate threads. You need a custom
    classloader because if you launch you .jar from (for
    example) "D:\myJar\Outer.jar" and specify the
    classpath (in the JAR manifest file) to (for example)
    "lib/Inner1.jar" it won't look at the JAR file entry
    "lib/Inner1.jar" it will look in
    "D:\myJar\lib\Inner1.jar". You're going to have
    problems though because you're basically running 3
    programs in 1 JVM. Things like static variables and
    security are going to be an issue. Basically unless
    there is a very good reason to do this, it sounds like
    a bad idea.
    2. Yes.

  • How to ban extracting from .jar file?

    Hello
    Problem of .jar file is: .class files can be extracted (with winrar ...) and decompiled. I don't want my classes to be decompiled. But I still need my jar executable of course.
    Is some solution which bans extraction without any impact on executability?
    Thank you very much.
    Tony

    Is some solution which bans extraction without any
    impact on executability?Hmmmm you could not put any class files in your jar. That would eliminate the extraction problem. Probably would be detrimental to execution.
    What do you think happens when your app runs? It just magically knows about your classes without extracting them?
    Not so much no.
    Use an obfuscator.
    Or if that's not good enough use another language or just panic.

  • Extract a jar file

    Hi Everyone,
    I have a .jar file which contains some java packages. How can extract this file to view the package contents.
    Thanks a lot.
    Hung

    You can open the jar file with an extraction program (like winzip, or tar) or you can try
    jar -xvf [jarfile]
    from the command line

  • Nested JAR file

    Hi,
    I have two JAR files - db.jar & dbserver.jar. This db.jar is nested inside dbserver.jar. And, I place db.jar file in the Manifest file's Class-Path Attribute as this.
    Manifest-Version: 1.0
    Class-Path: db.jar;
    Main-Class: suncertify.db.server.DataServerService
    When, I run this executable JAR as
    java -jar dbserver.jar
    I get this message, "Failed to load Main-Class manifest attribute from dbserver.jar"
    It not possible for me to have both "Class-Path" & "Main-Class" in my menifest file.
    How to solve this problem, am i making any mistakes?
    Thanx. in Advance,
    Shankar S

    You cannot put a jar inside a jar and expect it to run w/o a custom classloader. Sorry. Besides, your Main-Class attribute is set incorrectly anyway, it needs to be a path like you have but change the dots into forward slashes. This is what the error was trying to tell you.
    -Ron

  • I can't extract any .jar files?

    Hey,
    I think I have all the runtimes installed. Trying to install the ajax blueprints package. If I double click the jar file nothing happens. If I do a "java -jar package.jar" I get this
    C:\java>java -jar bpcatalog-1.0.1_02-installer.jar
    Exception in thread "main" java.lang.UnsupportedClassVersionError: bpcatalog (Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I also get something similar trying to install glassfish :(
    Thanks
    Craig

    This error
    Exception in thread "main" java.lang.UnsupportedClassVersionError: bpcatalog (Unsupported major.minor version 49.0)
    means you're trying to use a Java version earlier than 1.5.0 to manipulate Java classes that were compiled with 1.5 - the older version can't understand the newer class files.
    You'll probably need to change to the current Java version.

  • How to extract JAR file in particular directory

    Hi,
    I am extracting a JAR file(A.jar) in a Makefile
    Now the path of the Makefile is say /home/developer/
    The location of the JAR file is in /opt/tools/mk/A.jar
    I am extracting the jar file as:
    jar xvf /opt/tools/mk/A.jar
    This creates a directory named "A" under /home/developer, since the location of the Makefile is at /home/developer.
    Question) How do I unjar /opt/tools/mk/A.jar under /opt/tools/mk/ itself, irrespective of the location of the Makefile?
    thanks

    jar -?
    Usage: jar {ctxu}[vfm0Mi] [jar-file] [manifest-file] [-C dir] files ...
    Options:
        -c  create new archive
        -t  list table of contents for archive
        -x  extract named (or all) files from archive
        -u  update existing archive
        -v  generate verbose output on standard output
        -f  specify archive file name
        -m  include manifest information from specified manifest file
        -0  store only; use no ZIP compression
        -M  do not create a manifest file for the entries
        -i  generate index information for the specified jar files
        -C  change to the specified directory and include the following fileI'd say you may want to try the -C option

  • Extract a jar  from one place and put extracted files in another place

    Hi,
    I need to extract a jar file from one location ie source and to keep the extracted in another place ie destination directory.Is there any command in jar or can any one give java codings to perform this.
    Thanks in advance
    Vindo

    Do you mean....
    cd directory/to/place/extracted/files
    jar xf full/path/to/yourjarfile.jar

  • Extract jar file

    how do i expand/extract a .jar file so i can read all the classes and figure out how the program works?

    Open it with winzip/winrar. Extract all the class files. Run a Java decompiler on them.
    If you weren't able to figure this out though, you're probably not going to understand the decompiled code.

  • Jar file Extraction in different directory...

    Hi friends..
    i want to extract a jar file using a java program..but not in current directory..i want it to do in another directory..
    i tried it using exec(jarfilename,env var,filedirectory) ..but it is not working..help me..
    thanks..
    Krishna

    Hi Krishna,
    The following code will definitely help you
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    * @author Snehanshu
    public class Main {
         * Extracts a zip file
        public void extractZipFile() {
            try {
                String zipFileName = "C:\\DEMO.jar";
                String extractedFileName = "C:\\extracted.txt";
                //Create input and output streams
                ZipInputStream inStream = new ZipInputStream(new FileInputStream(zipFileName));
                OutputStream outStream = new FileOutputStream(extractedFileName);
                ZipEntry entry;
                byte[] buffer = new byte[1024];
                int nrBytesRead;
                //Get next zip entry and start reading data
                if ((entry = inStream.getNextEntry()) != null) {
                    while ((nrBytesRead = inStream.read(buffer)) > 0) {
                        outStream.write(buffer, 0, nrBytesRead);
                //Finish off by closing the streams
                outStream.close();
                inStream.close();
            } catch (IOException ex) {
                ex.printStackTrace();
         * @param args the command line arguments
        public static void main(String[] args) {
            new Main().extractZipFile();
    }Change the "extractedFileName" as you want.
    :)

  • Extracting contents of a jar file

    I try to extract a jar file:
    # jar -x Atheon.jar
    it just doesn't do anything.
    LOL. Im retarded. what am i doing wrong?

    You expect an answer in 25 minutes on a Sunday?
    Try telling jar that you're giving it a filename rather than piping stuff into it: jar xf myFile.jar

  • Application works in jdeveloper but not as standalone jar file

    Hi All
    We have developed an application using BI Publisher APIs,it works as expected through JDevelper,however when I try to deploy it to a jar file a run it through command line it gives me No class found exception for
    javax/xml/rpc/Service class factory.. thinking that the class is not present.I have extracted the jar file but could find the class file in the expected directory........anyhelp would greatly be appreciated.
    Regards
    Venkatesh

    Hi Venkatesh,
    Few questions.
    1. What is your JDeveloper version? (Always better to post your JDev version along with the question, which would help us to help you better).
    2. Did you try adding webserviceclient.jar to the classpath? (Search in your JDev installation directory for the location of this jar file).
    -Arun

Maybe you are looking for

  • Smart form with 2 different pages

    Hi Experts I have a requirement, I need to develop a smart form with 2 different pages, and each page has different data and presentation of the data also is different. In the first page I need to display the contract data with the line items and amo

  • Issues with NAS, iPhoto, RAW file format, AEBSn, Leopard

    I think I've isolated it down to a networking stack issue with Leopard, but I was hoping I could get some more thoughts/advice. I don't want to downgrade to Tiger, but I may need to! Either that or host my iPhoto library locally. Scenario: My iPhoto

  • Ipod video and USB 1.0...

    I purchased a 60Gb Ipod as a gift and I have come to find out that my daughter's IMac has USB 1.0. Can she use it? An Apple store person said she would have to buy a new computer. The tech specs on the Apple site say 2.0 Recommended but it does not s

  • Displaying zero in the query

    Hi, I have defined a query with one characteristic (Material) in row and 3 key figures (Price in current month, Standard price and quantity) in column. Moreover there is one calculated key figure (deviation) = (Price in current month -Standard price)

  • Sub screen: Layout changed after applying the Patches

    Hi, I created a sub screen and used the same in a standard screen. The issue is that when I compare the screens i.e. the layout of the sub screen and where it is actually used(standard screen), they differ. The sub screen was being displayed properly