The Artima Developer Community
Sponsored Link

Java Answers Forum
Extract a JAR File Programmatically

2 replies on 1 page. Most recent reply: Jan 9, 2003 8:23 AM by Bankole

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Bankole

Posts: 2
Nickname: banky
Registered: Jan, 2003

Extract a JAR File Programmatically Posted: Jan 8, 2003 2:55 PM
Reply to this message Reply
Advertisement
I need some help with extracting a JAR file programmatically without using the jar -xf command in a case where the system might not be able to run the jar -xf command. How do I do that? Some ideas!


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Extract a JAR File Programmatically Posted: Jan 9, 2003 1:54 AM
Reply to this message Reply
have a look at the class : java.util.jar.JarFile

Bankole

Posts: 2
Nickname: banky
Registered: Jan, 2003

Re: Extract a JAR File Programmatically Posted: Jan 9, 2003 8:23 AM
Reply to this message Reply
Is there anything I am doing wrong with this code :
try
      {
		  // a jar file
   		  String jarFileName;
 
   		  jarFileName = args[0];
 
		  //File file = new File(jarFileName);
		  JarFile jarFile = new JarFile(jarFileName);
		  System.out.println("Manifest Name: " + jarFile.MANIFEST_NAME);
		  Enumeration jarContents = jarFile.entries();
		  while(jarContents.hasMoreElements())
		  {
			  ZipEntry zipVersion = (ZipEntry)jarContents.nextElement();
			  System.out.println("ZipFile: " + zipVersion);
		  }
 
          // extract jar file contents and put them into the hashtable.
          FileInputStream fileStream = new FileInputStream(jarFileName);
          BufferedInputStream buffStream = new BufferedInputStream(fileStream);
          ZipInputStream zipStream = new ZipInputStream(buffStream);
          ZipEntry zipEntry = null;
          while ((zipEntry = zipStream.getNextEntry())!= null)
          {
          	  System.out.println("zipEntry Name = "+zipEntry.getName() +
          	  							", " + "zipEntry Size = "+ zipEntry.getSize());
	  	  }
       } catch (NullPointerException e) {
          System.out.println("done.");
       } catch (FileNotFoundException e) {
          e.printStackTrace();
       } catch (IOException e) {
          e.printStackTrace();
       }
 


I keep getting this error:

C:\JAVA>java TestJarExtract TEST.JAR
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:138)
at java.util.jar.JarFile.<init>(JarFile.java:80)
at TestJarExtract.main(TestJarExtract.java:21)

What could be going wrong with the code. I am trying to get
each entry and place it in the right directory instead of using jar -xvf command in a case where the system does not have the jar command

Flat View: This topic has 2 replies on 1 page
Topic: Java Assignment Help (Urgent!) Previous Topic   Next Topic Topic: weblogic settings

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use