Extract JAR file to a different directory

Is it possible to use the jar command to extract the content of a JAR file to a different directory (not the current directory)?
I want to use this command inside a makefile, looking for the same effect as "unzip example.jar -d directory".
Thanks in advanced.

Thanks Chuck, you solved my doubt... It surprises me that JAR doesn't support this option.
I used the "unzip" command inside the makefile instead, but I wanted to be sure that there wasn't any chance to use "jar" (without using the additional script file).

Similar Messages

  • How to extract jar files into  a folder in the local disk and then import?

    hai forum,
    will any one tell me how should i extract jar files into a location in my project folder and then how to import the class files for further usage?
    Thank you .

    I will be graeateful if u could explain this a bit.
    Do you want to say that i should craete instance of
    ZipEntry like this
    InputStream is =
    jarFile.getInputStream(entry);
    File inputFile = new
    File("C:\\myclasses.data");
    FileInputStream fis=
    new FileInputStream(inputFile);No! You need to write the entry using FileOutputStream copying all the bytes of the ZipEntry InputStream to the FileOutputStream.
    >
    What about adding into a directory?Do i have to
    create on dynamically?Yes! You can use File.mkdirs(). For example
                        File ofile = new File("your directory where you will place the zip entries" + zipEntry.getName());
                        ofile.getParentFile().mkdirs();

  • 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

  • Download and extract jar file from applet

    Can any one provide me a solution for my below problem. Thanks in advance for all the suggestions.
    I want my applet to download a jar file, extract into users home directory by creating a folder and then set the created folder to java library path.
    My applet html file is in "root" directory. The applet is included into applet.jar and placed under "lib" directory which is under "root" directory.
    Now i also had another jar file(contains dlls what I packed) under the same lib folder.
    The below is the following directory structure in my server.
    root ---
         |
         |
         default.html
         lib--
         |
         |
         applet.jar - contains applet related classes
         native.jar - contains dlls which are to be loaded
    When a client downloads my applet, it should copy the native.jar and then extract into a new folder under user home directory. Then set this folder to java library path.
    Regards
    raman kumar

    I managed to do it this way, Just remember that you need to sign the jar files for your applet, else it won't work.
    package jar.extract;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.jar.JarFile;
    import java.util.zip.ZipEntry;
    public class JarExtractor {
         // Dll file in the jar
         private static String JAR_FILE = "dll.jar";
         public void extract() {
              try {
                   JarFile jf = new JarFile(JAR_FILE);
                   // Entry in the jar file rember package and dll file
                   ZipEntry ze = new ZipEntry("package/dll_file");      
                   int length = (int) ze.getSize();
                   byte fileContent[] = new byte[length];
                   InputStream fin = jf.getInputStream(ze);
                   fin.read(fileContent, 0, length);
                   // CODE missing.
                   // You need to write the input stream (fin) to a new files output stream
                   // it is like copying a file !!!
              } catch (IOException e) {
                   e.printStackTrace();
    }Tom

  • Extracting JAR files and reading their contents

    Hi,
    I have a JAR files which contains classes in different packages also a config file which is also in some package structure.
    I have to read that config file, which will inturn have other file names, i have to read the filename and read the actual content of the file spcified in the config file.
    Can some one help me out with a simple example... ?
    I have tried with java.util.zip... I can read the name of all the files in JAR to any depth.. but couldn't open and read the required file.
    Thanks in advance...
    Thanks & Regards,
    Gurushant Hanchinal

    Hello you can see the content of a jar file with this line
    jar tf filename.jarand extract with
    jar xf filename.jar

  • Jar File caching in temp directory problem

    Hello,
    I have a problem where the java plugin is caching jar_cache9999.jar (where 9999 is any number 0-9) files in the temp directory. I have tried following the directions for disk caching in the documentation, but these files are always created, never destroyed.
    I was wondering:
    1. Is there a simple setting that I could set that should resolve this problem? (un-setting "cache jars in memory" wouldn't seem to solve the problem as I would think that would only force the browser to use the same jar if it had already been loaded)
    2. Has this problem been corrected in later releases of the java plugin? I am using the jre1.2.2. When I looked at the problem here in the forums, the bug that was listed was listed as fixed.
    Thanks,
    Dan Hughes

    Hi,
    Java Plug-in has supported disk caching in previous versions by using the same cache the browser uses for all other web documents. This works for casual applet usage, but larger applets can often get flushed from the cache to make room for other documents since the browser has no knowledge that an applet file might be needed in the future. The result is that this caching strategy fails where is needed most in large business applets.
    From 1.3. the new feature is activated by including the new "cache_option" , "cache_archive" and "cache_version" values in the EMBED/OBJECT tag that specifies the use of Java Plug-in as below:
    <OBJECT ....>
         <PARAM NAME="archive" VALUE="...">
         <PARAM NAME="cache_option" VALUE="...">
         <PARAM NAME="cache_archive" VALUE="...">
         <PARAM NAME="cache_version" VALUE="...">
    </OBJECT>
    or
    <EMBED ....
         archive="..."
         cache_option="..."
         cache_archive="..."
         cache_version="...">
    For detail description please go through the following URL:
    http://java.sun.com/products/plugin/1.3/docs/appletcaching.html
    Hope this will help you.
    Anil.
    Developer Technical Support
    Sun Microsystems,
    http://www.sun.com/developers/products

  • 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.

  • Publish a file to a different directory.

    I've seen other questions similar to mine on the forums but haven't found an answer.  My site has a newsletter archive that links to all of our past newslettters.  The newsletters are just html files saved from emails we send out.
    To keep things organized, the newsletters are grouped by year, so all 2010 newsletters are saved in the 2010 directory.  However, when I add the newsletter using the Link to File on My Computer, it adds the newsletter html file to the current directory.
    Is there any way, without using an outside FTP program, to upload the newsletter to the 2010 directory and then link to it from the main newsletter archive page?  I can't use the administer->file placement option because the rule  only applies to this specific upload. This seems like it should be an obvious, simple thing, but I'm stumped.

    Hi,
         As of now I do not think this is possible in Contribute. But there can be a work-around.Can you try the following steps:
    When you edit a web page, add the links to the files in your computer.
    Do Publish As New Page (File -> Actions -> Publish As New Page), and select the Folder in which you want to publish your pages to, by clicking the Choose Folder button.
    The web page and all the files from your computer will be published to that folder.
    Now, re-edit the published web page with the links, and Publish As New Page to the original folder in which the web page was present.
    This is a long workaround, where you will be publishing the web page twice. Hope this helps.

  • How can I redirect Batch Report Files to a different directory.

    I have a custom version of the Batch Process Model that allows for on the fly report updates. At the end of execution the final report is written. I need to redirect this final report to another directory, but I am having trouble identifying where the report directory is specified. Right now, it is writing in the same directory as the sequence file and I need to change this.

    Hi Terry,
    have a look at the following inside the process model TestUUTs (or Single Pass)
    Locals.ModelData.ReportOptions.DirectoryType
    set this to "SpecificDirectory"
    then in
    Locals.ModelData.ReportOptions.Directory
    set this to your target directory.
    If it's a permanent setting, then I'd suggest updating these values before run time in the report options panel from the Configure menu option.
    If it can be determined before the sequence is run, then you could do it as part of the report options callback. Otherwise, slot it in as and when needed, just before the call to the Determine Report File Path and Determine UUT Report File Path steps, although I guess that depends on how much you've modified the process model so far.
    Hope that helps
    S.
    // it takes almost no time to rate an answer

  • File name in different directory

    i have a problem when saving files:
    I copied all the files from one directory to another ---with the same file name and I tried to make chnages in the new directory, But I found that all the changes I made in the new directory also happened in the old directory. So Labview recogonize file names only, not file paths. I don't like this feature!!!!!

    This is an old problem with no easy solution as of now. For a better description of what is going on here, you can read this discussion where I answered a similar question a while ago.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Parsing XML with DTD residing in jar file

    Hi,
    I have problems using crimson parser for my program under JDK 1.4.0b2. It attempts to parse an xml file with SAX. The corresponding lies in a jar file in a different directory but reachable through the classpath. All I get is an exception.
    org.xml.sax.SAXParseException: Relative URI "my.dtd"; kann nicht ohne eine Dokument-URI aufgel�st werden.
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3121)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3115)
    at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2702)
    at org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2674)
    at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1125)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
    at org.xml.sax.helpers.XMLReaderAdapter.parse(XMLReaderAdapter.java:223)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:326)
    I used Xerces before and it worked fine. I already searched the community for that problem. All hints I found assume that xml file and dtd are in the same directory. Setting the systemId of the input source doesn't fix the problem.
    Is there anyone out there knowing what to do?
    Thanks,
    Thorsten

    Use a Resolver to map a PUBLIC name to a local name:
    <!DOCTYPE DOC PUBLIC "-//gaskin.de//XMLDOC 1.0//EN"
    "http://www.gaskin.de/dtd/xmldoc.dtd">
    public static register() {
       ClassLoader loader = Resolver.class.getClassLoader();
       registerCatalogEntry(
          "-//gaskin.de//XMLDOC 1.0//EN",
          "de/gaskin/resources/dtd/XMLDOC.DTD",
          loader);
    }

  • 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!

  • Extract contents of a .Jar file or executable jar file

    I have an executable Jar file.. Is there anyway that I can see the contents of this file.. the code in it..
    I have read some tutorials on how to extract .jar files but the question is where do i execute these commands.. is it on the command window or somewhere else.
    Can anyone help me plz????????

    but the question is where do i execute
    these commands.. is it on the command window or
    somewhere else.
    If you're using windows OS, you can do execute the
    command in dos promt
    and if you're using linux, you execute it in the
    Terminal/Console or double click on the file name in
    the
    Knoqueror, you can see the contents.Konqueror file manager,you can see the contents.

  • Servlets in Jar files  in WLS 6.1 ?

    Trying to port a WLS 5.1 servlet into 6.1 (an entirely different
              animal it appears)
              I have added an application to my config.xml file as below as well as
              trying to start it
              PasswordPolicy="wl_default_password_policy"
              Realm="wl_default_realm"/>
              <Application Deployed="true" Name="DefaultWebApp_cb2java"
              Path=".\config\PM\applications">
              <WebAppComponent Name="DefaultWebApp_cb2java"
              Targets="PCPNEARN"
              URI="DefaultWebApp_cb2java" WebServers="PCPNEARN"/>
              </Application>
              <StartupClass Arguments="servlet=ProMan"
              ClassName="weblogic.servlet.utils.ServletStartup"
              FailureIsFatal="true" Name="StartPMServlet1"
              Targets="PCPNEARN"/>
              Now my servlet is packaged in a JAR file under the lib directory of so
              when I assume that WLS will automatically pick this up from
              C:\Weblogic6.1\wlserver6.1\config\PM\applications\DefaultWebApp_cb2java\WEB-INF\lib
              directory ? ( as the lib directory is where the doc says it picks up
              jar files from )
              Now when I start WLS it cant find the servlet? Is that because I cant
              package it in a JAR as of WLS 6.1 and have to move the class files to
              the Classes directory instead ?
              Furthermore the Servlet itself references JavaBeans deployed in a
              totally different application. Can I also assume that if I have my
              Classpath correct these will get picked up ?
              

    I would look here
    http://e-docs.bea.com/wls/docs61/webapp/security.html#100365 for methods on
    protecting web app resources.
    "zhen Ni" <[email protected]> wrote in message
    news:3c86d70c$[email protected]..
    Hello:
    I have some derectories and files on my web site,and only appointed usersstored in my database can access their special directories.how can i do?
    thank u!

  • Accessing web application JAR files from applet

    I've got an applet which is part of a web application.
    All the web application JARs are in the webapps/myappl/WEB-INF/lib directory, and I
    can't seem to place anything in that directory on the archive attribute of <OBJECT> tag.
    I'm running into trouble because I'm sending objects from the servlet to the applet and keep getting classnot found during deserialization because I've missed some jar file on the archive attribute. I've had to copy lots of jar files up to where the codebase in the HTML file is to make this run. My question is this.
    Is it better to just change the tomcat security policy file (catalina.policy in tomcat conf directory) so that the JARs are directly accessible and I don't have to copy them from WEB-INF/lib???? Has anyone done this before? What would the line look like?
    I'm assuming that I have to follow the instructions (THAT I DON'T UNDERSTAND)
    at the bottom of the policy file. Can someone help me out here????
    should I have something like
    grant codeBase "file:${catalina.home}/webapps/myappl/WEB-INF/classes/-"
    { permission java.security.AllPermission; };
    grant codeBase "file:${catalina.home}/webapps/myappl/WEB-INF/lib/-"
    { permission java.security.AllPermission; };
    Will this allow me to place references to jar files (and the classes directory) in the archive attribute, such as
    <OBJECT .....  >
        <param name="archive" value="../WEB-INF/lib/applet.jar,../WEB-INF/lib/someapp.jar,../WEB-INF/classes" />trailer for catalina.policy is
    // You can assign additional permissions to particular web applications by
    // adding additional "grant" entries here, based on the code base for that
    // application, /WEB-INF/classes/, or /WEB-INF/lib/ jar files.
    // Different permissions can be granted to JSP pages, classes loaded from
    // the /WEB-INF/classes/ directory, all jar files in the /WEB-INF/lib/
    // directory, or even to individual jar files in the /WEB-INF/lib/ directory.
    // For instance, assume that the standard "examples" application
    // included a JDBC driver that needed to establish a network connection to the
    // corresponding database and used the scrape taglib to get the weather from
    // the NOAA web server.  You might create a "grant" entries like this:
    // The permissions granted to the context root directory apply to JSP pages.
    // grant codeBase "file:${catalina.home}/webapps/examples/-" {
    //   permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
    //   permission java.net.SocketPermission "*.noaa.gov:80", "connect";
    // The permissions granted to the context WEB-INF/classes directory
    // grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/classes/-" {
    // The permission granted to your JDBC driver
    // grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/lib/driver.jar" {
    //   permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
    // The permission granted to the scrape taglib
    // grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/lib/scrape.jar" {
    //   permission java.net.SocketPermission "*.noaa.gov:80", "connect";
    // };

    Thank you for your reply.
    As I mentioned in my first post I had seen a couple of posts mentioning ServletContext before, but dismissed them as I am not using any servlets of my own. However, since you showed me exactly how it was used I realised I could probably just use a dummy servlet to get this information.
    The following page suggests a couple of techniques for doing just this.
    http://www.jguru.com/forums/view.jsp?EID=1087411
    So I think that's me sorted, cheers.

Maybe you are looking for