Results 1 to 5 of 5
  1. #1
    drdexter33 is offline Member
    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Default How to include a zip archive in a Java Executable

    I am looking for an example of how to add a zip archive file as a resource to a Java program when it is compiled.

    The purpose of this is to allow an end-user to run a Java form which extracts and compiles the contents of the zip file (some type of script[s]) on a machine with a Java run-time installed.

    Thanks in advance for any help.

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to include a zip archive in a Java Executable

    That depends on your build tool. In Eclipse, just put it in the source folder and it will be incorporated into exported jars. I like to set up a second source directory in my Eclipse projects, so the actual source is in src/ and the resources are in res/.
    Get in the habit of using standard Java naming conventions!

  3. #3
    drdexter33 is offline Member
    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Default Re: How to include a zip archive in a Java Executable

    Hi There..

    Thanks for your reply.

    I was able to add that zip file to a jar at the command line like this:

    jar -cf example.jar test.zip C:\Users\me\workspace\myJob\bin\test.class

    My next step is to write the Java to access that jar and unpack that zip to a directory.

    Any recommendations on the best way to do that?

    Thanks..
    Last edited by drdexter33; 03-17-2013 at 02:25 AM.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to include a zip archive in a Java Executable

    Check this out: java.util.zip (Java Platform SE 6)

    Here's how I access a gzip resource in one of my programs. I'm sure zip is similar.

    Java Code:
    new java.util.zip.GZIPInputStream(DemoLexer.class.getResourceAsStream("/krum/jtx/demo/lexer/DEFAULT.automaton.gz"))
    Get in the habit of using standard Java naming conventions!

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: How to include a zip archive in a Java Executable

    Just a side point but jar archives are a species of zip, so you aren't saving anything in terms of space by including a zip archive in your jar, rather than just including the contents of the zip archive.

Similar Threads

  1. create windows executable using executable jar file
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 09:29 PM
  2. Replies: 0
    Last Post: 03-02-2010, 09:28 AM
  3. Replies: 3
    Last Post: 09-07-2009, 09:27 AM
  4. include-prelude/include-coda
    By devin in forum Java Servlet
    Replies: 0
    Last Post: 02-11-2009, 08:33 PM
  5. jsp:include and include file
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-14-2007, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •