Enumerating Jar file entries

At the risk of invoking the wrath and contempt of forum watchers the world over, I wish to reopen this can of worms.
I'm writing a Java program to play cribbage, and I have finally succeeded in getting it to run as a jar. My package structure for the jar is as follows.
cribbage (contains all the cribbage-specific processing)
.....images (contains board.png)
cards (contains general card-related processing)
.....images (contains cards*.png, backs*.png)
common
.....util (contains combinatorial math routines)
If I run through the JarFile enumerating entries, it stops after cribbage/images. My first question is therefore "How can I get beyond cribbage/images and into cards/images, which is where I REALLY want to be?"
The cards/images part of it contains, at the moment 5 cards*.png and 3 backs*.png, defining different card face styles and card back collections, but I may wish to change those nmbers in the future, without hard coding names in the code. This is why I wish to enumerate these entries, to give a player the chance of choosing styles and card backs from a flexible set of alternatives.
Since I may write a program in future to play starchplonkers or gurglemuffins (both card games) I'd really like the card-related stuff to be separated from the cribbage stuff - same with the common stuff - but, as soon as I put cribbage into a jar I can't access any other locally written packages, unless someone can suggest a way of organizing packages more efficiently.
I have been programming for close to 40 years, but only recently decided to exploit certain aspects of Java, like packages and jars.

OK. First, here's the structure of the jar file:
F:\Java\Packages>jar tf Cribbage.jar
META-INF/
META-INF/MANIFEST.MF
cribbage/CardPanel.class
cribbage/Cribbage$1.class
cribbage/Cribbage$CribbageCardComparator.class
cribbage/Cribbage$LogFileFilter.class
cribbage/Cribbage$MsgLineRenderer.class
cribbage/Cribbage.class
cribbage/CribbageBoard.class
cribbage/CribbageDealer$RecordedGame.class
cribbage/CribbageDealer$RecordedHand.class
cribbage/CribbageDealer.class
cribbage/images/
cribbage/images/board.png
cards/Card.class
cards/CardDeck.class
cards/CardFactory.class
cards/images/
cards/images/backs1.png
cards/images/backs2.png
cards/images/backs3.png
cards/images/cards1.png
cards/images/cards2.PNG
cards/images/cards3.PNG
cards/images/cards4.png
cards/images/cards5.png
common/util/Combinations.class
common/util/Derangements.class
common/util/Hex.class
common/util/Ordinal.class
common/util/Permutations.class
common/util/StringKit.class
common/util/TestCombinations.class
..and the code:
try {
JarFile jarfile = new JarFile( "cribbage/Cribbage.jar" );
Enumeration<JarEntry> entries = jarfile.entries();
while ( entries.hasMoreElements() ) {
JarEntry entry = entries.nextElement();
System.out.println( "Entry: " + entry + ", " + entry.getName() );
} // while
} catch (IOException e) {
e.printStackTrace(System.err);

Similar Messages

  • Jar File Entry Names (separator)

    How goes it everyone?
    I wrote some code to find a class on the classpath, which goes through the directories and jars on the classpath to find the class in question. It works fine on Linux but when I try to run it from a .jar on Windows it fails.
    I tracked this down to the fact the the File.separator for files on Linux and Windows is different (which the code takes into account), but the File.separator for entries in a jar file is "/" on both. Anyone know if this is always the case, like on IRIX, Solaris and Macs? Is there a constant like JAR_FILE_SEPARATOR or something?
    I looked around for some documentation on the subject but couldn't find an authority on the subject. 2 DD's to the first with a link.
    Josh

    you may use the special .jar tool to do it.
    www.pivotonic.com
    JavaJar1.1
    you can add files to .jar file like winzip.
    and you can edit and check correct the manifest file in JavaJar editor.
    why not try it?

  • Jar file entry - file on users machine

    Hi,
    I am having trouble with the formatting of a file when I attempt to copy it from a jar file to a user directory. It copies the file to the correct dir, but somehow removes all newlines. Does anyone know what I am doing wrong?
    The code is posted below. The ResourceManager just uses the getClassLoader().getResourceAsStream() method to return an InputStream object to the jarred-up file.
      public static void loadLocalDatabase()
        try
          File rootdirectory = new File(getRootDir());
          if(!rootdirectory.exists())
            rootdirectory.mkdir();
          // load the database file from the local database jar
          // into a file on the users local machine
          File output = new File(rootdirectory, databaseFilename);
          if(output.exists())
            return; // if the database file exists, we dont want to overwrite it
          FileInputStream databaseOriginal = new FileInputStream(ResourceManager.getInputStream(databaseFilename));
          byte[] file = new byte[databaseOriginal.available()];
          databaseOriginal.read(file);  // put the contents into the array
          FileOutputStream fos = new FileOutputStream(output); // write the contents out.
          fos.write(file);
          fos.flush();
          fos.close();     
        catch(Exception e)
          System.out.println(e.getMessage());
          e.printStackTrace();
      }Thanks,
    Dave Smith

    Ah. Just a little update: that FileInputStream should just be an InputStream

  • Executing java apps without individual JAR file entries in CP???

    Hi all,
    I'm used to having to specific EACH separate jar file in the CLASSPATH when executing a java application. See the batch file example below.
    Is there a way to not have to spell out EACH JAR file separately in this fashion? Eg just refer to the JAR directory?
    What do people usually do here when delivering a java application to someone else, given the application has your own class files in a JAR, plus other 3rd party class files? Do you always have to build up a long JAVA batch file like the one below to enable the application to be run?
    -----------example-------
    c:\Progra~1\jdk1.3.1\bin\java -classpath .;deploy\mail.jar;deploy\activation.jar;deploy\xerces.jar;deploy\commons-digester.jar;deploy\commons-collections.jar;deploy\commons-beanutils.jar sns
    Cheers
    Greg

    A simple way is to have a class inside your program load all the JAR files needed.
    That way, when the main class file starts, place a call to the class that will load
    the classes for you. Like this one below...
    import java.lang.*;
    public class MyJarLoader {
    public MyJarLoader() {
    System.load(String); // replace 'String' with the file pathname of a JAR file.
    // you will need to do this for each JAR file, just add another call to System.load() here

  • How do I prevent Spotlight from categorizing 'JAR' files as 'Application'

    I'm a java developer and consequently I have a lot of JAR files on the filesystem. The JAR file format is a standard archive format for java, and is used mostly to package library code - the java equivalent of a DLL. They can also be created as 'executable JAR's, but this is (very) infrequent compared to the library usage.
    Spotlight seems to think every JAR file is an application, and because I have a lot of java applications and development stuff installed, I can no longer reliably use Spotlight to find actual applications because the search results are overflowing with useless JAR file entries.
    Is there any way to configure spotlight to not classify JARS as applications? Or, alternately, can I make Spotlight ignore JARs completely? Either would save me a lot of time..
    /Bill

    There are several things in the current version of Spotlight that are either broken or just plain wrong. It looks like you have found another. When I look at the metadata for a jar file I see that its type is, well, a java jar file, and its content tree declares it to be a com.sun.java-archive. Finder gets this right: if you do GetInfo on such a jar file its kind is shown as "Java JAR file"--as it should be.
    When I made a saved search, using the Kind drop-down menu to get the pre-defined Application, and then looked to see what criteria Spotlight was using to define "application" (and yes, the search included jar files in its results), I discovered Spotlight was NOT using the simple, straightforward "kMDItemKind=Application" as one would expect. Instead it is using something I had never heard of to define an Application, to wit "_kMDItemGroupId = 8"--furthermore, I believe characterizing applications that way has been deprecated. Be that as it may, it doesn't work to find the things you want, and exclude the things you don't.
    There is no way for a user to fix this. The only thing you can do is not let Spotlight define the kind. Thus, if you bring up a search window do not use the Kind drop-down menu to select Application. Instead select Other from the menu and then type Application. You then get only things whose type declaration is Application, and you don't get jar files or widgets.
    The other option is to exclude jar files by typing
    NOT jar
    in the search for box (you'll still get widgets though). You can also add that boolean restriction if you are using the menu bar Spotlight search.
    Francine
    Francine
    Schwieder

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

  • *.jar file association setting

    I use J2Sdk1.3.1_04 with Windows XP professional. I have a problem with the *.jar file association setting and I need someone's help on how to correct this. Anyone?

    In Windows Explorer menu: Tools | Folder Options | File Types, select jar file entry, click Advanced, and use what I posted to for the open action.

  • Add entries to a Jar-File

    I try to add an entry to a jar File,
    by using the following code:
    String jarFile = new String("/home/xyz/test.jar");
    JarOutputStream jos = new JarOutputStream (new FileOutputStream(jarFile));
    /* this one doesn't work either ->
    * the jar file is damaged after this...
    * JarOutputStream jos = new JarOutputStream (new FileOutputStream(jarFile,true));
    JarEntry newEntry = new JarEntry("test.class");
    jos.putNextEntry(newEntry);
    //...write something in new Entry...
    jos.close();But instead of appending the new entry, the code overwrites the file test.jar with a new archive.
    any ideas would help me very much ! thx !

    You cannot simply append an entry to a jar file (not by using JarOutputStream or any of the standard classes offered by Java). You'll have to read and rewrite the whole jar or use some other implementation.
    Alin.

  • "no manifiest section for signature file entry" when run the Jar file

    I built an application by using JBuilder 8.0 and it works fine. But when I deploy it into a jar file, whenever I run it, the following exception appears:
    Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry javax/security/cert/Certificate.class
    at sun.securtiy.util.SignatureFileVerifier.verifySection
    Because I didn't do anything about the security when build the application. I am really confused. Can somebody help?

    I had a similiar problem using NetBeans. There must be a way to view the properties of your jar from Jbuilder and set its manifest. I am very new to this myself, but all I did was edit another manifest and copied into mine. Here is my example manifest:
    Manifest-Version: 1.0
    Main-Class: J3Ed
    The first line is the default line for a manifest. It is very simple and there is much more that could be added, but is not always necessary. I recommend reading the documentation :
    http://developer.java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html
    Also if you have an archiving utility such as powerarchiver or winzip, open your JAR and check to see that you have a MANIFEST.MF file. If you do then edit it where needed, if not create one and its relative location should be set to META-INF/MANIFEST.MF.
    Hope this helps.

  • Loading jar files at execution time via URLClassLoader

    Hello�All,
    I'm�making�a�Java�SQL�Client.�I�have�practicaly�all�basic�work�done,�now�I'm�trying�to�improve�it.
    One�thing�I�want�it�to�do�is�to�allow�the�user�to�specify�new�drivers�and�to�use�them�to�make�new�connections.�To�do�this�I�have�this�class:�
    public�class�DriverFinder�extends�URLClassLoader{
    ����private�JarFile�jarFile�=�null;
    ����
    ����private�Vector�drivers�=�new�Vector();
    ����
    ����public�DriverFinder(String�jarName)�throws�Exception{
    ��������super(new�URL[]{�new�URL("jar",�"",�"file:"�+�new�File(jarName).getAbsolutePath()�+"!/")�},�ClassLoader.getSystemClassLoader());
    ��������jarFile�=�new�JarFile(new�File(jarName));
    ��������
    ��������/*
    ��������System.out.println("-->"�+�System.getProperty("java.class.path"));
    ��������System.setProperty("java.class.path",�System.getProperty("java.class.path")+File.pathSeparator+jarName);
    ��������System.out.println("-->"�+�System.getProperty("java.class.path"));
    ��������*/
    ��������
    ��������Enumeration�enumeration�=�jarFile.entries();
    ��������while(enumeration.hasMoreElements()){
    ������������String�className�=�((ZipEntry)enumeration.nextElement()).getName();
    ������������if(className.endsWith(".class")){
    ����������������className�=�className.substring(0,�className.length()-6);
    ����������������if(className.indexOf("Driver")!=-1)System.out.println(className);
    ����������������
    ����������������try{
    ��������������������Class�classe�=�loadClass(className,�true);
    ��������������������Class[]�interfaces�=�classe.getInterfaces();
    ��������������������for(int�i=0;�i<interfaces.length;�i++){
    ������������������������if(interfaces.getName().equals("java.sql.Driver")){
    ����������������������������drivers.add(classe);
    ������������������������}
    ��������������������}
    ��������������������Class�superclasse�=�classe.getSuperclass();
    ��������������������interfaces�=�superclasse.getInterfaces();
    ��������������������for(int�i=0;�i<interfaces.length;�i++){
    ������������������������if(interfaces[i].getName().equals("java.sql.Driver")){
    ����������������������������drivers.add(classe);
    ������������������������}
    ��������������������}
    ����������������}catch(NoClassDefFoundError�e){
    ����������������}catch(Exception�e){}
    ������������}
    ��������}
    ����}
    ����
    ����public�Enumeration�getDrivers(){
    ��������return�drivers.elements();
    ����}
    ����
    ����public�String�getJarFileName(){
    ��������return�jarFile.getName();
    ����}
    ����
    ����public�static�void�main(String[]�args)�throws�Exception{
    ��������DriverFinder�df�=�new�DriverFinder("D:/Classes/db2java.zip");
    ��������System.out.println("jar:�"�+�df.getJarFileName());
    ��������Enumeration�enumeration�=�df.getDrivers();
    ��������while(enumeration.hasMoreElements()){
    ������������Class�classe�=�(Class)enumeration.nextElement();
    ������������System.out.println(classe.getName());
    ��������}
    ����}
    It�loads�a�jar�and�searches�it�looking�for�drivers�(classes�implementing�directly�or�indirectly�interface�java.sql.Driver)�At�the�end�of�the�execution�I�have�found�all�drivers�in�the�jar�file.
    The�main�application�loads�jar�files�from�an�XML�file�and�instantiates�one�DriverFinder�for�each�jar�file.�The�problem�is�at�execution�time,�it�finds�the�drivers�and�i�think�loads�it�by�issuing�this�statement�(Class�classe�=�loadClass(className,�true);),�but�what�i�think�is�not�what�is�happening...�the�execution�of�my�code�throws�this�exception
    java.lang.ClassNotFoundException:�com.ibm.as400.access.AS400JDBCDriver
    ��������at�java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    ��������at�java.security.AccessController.doPrivileged(Native�Method)
    ��������at�java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    ��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    ��������at�sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    ��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    ��������at�java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    ��������at�java.lang.Class.forName0(Native�Method)
    ��������at�java.lang.Class.forName(Class.java:140)
    ��������at�com.marmots.database.DB.<init>(DB.java:44)
    ��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
    ��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
    ��������at�com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
    ��������at�com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
    Driver�file�is�not�in�the�classpath�!!!�
    I�have�tried�also�(as�you�can�see�in�comented�lines)�to�update�System�property�java.class.path�by�adding�the�path�to�the�jar�but�neither...
    I'm�sure�I'm�making�a/some�mistake/s...�can�you�help�me?
    Thanks�in�advice,
    (if�there�is�some�incorrect�word�or�expression�excuse�me)

    Sorry i have tried to format the code, but it has changed   to �... sorry read this one...
    Hello All,
    I'm making a Java SQL Client. I have practicaly all basic work done, now I'm trying to improve it.
    One thing I want it to do is to allow the user to specify new drivers and to use them to make new connections. To do this I have this class:
    public class DriverFinder extends URLClassLoader{
    private JarFile jarFile = null;
    private Vector drivers = new Vector();
    public DriverFinder(String jarName) throws Exception{
    super(new URL[]{ new URL("jar", "", "file:" + new File(jarName).getAbsolutePath() +"!/") }, ClassLoader.getSystemClassLoader());
    jarFile = new JarFile(new File(jarName));
    System.out.println("-->" + System.getProperty("java.class.path"));
    System.setProperty("java.class.path", System.getProperty("java.class.path")+File.pathSeparator+jarName);
    System.out.println("-->" + System.getProperty("java.class.path"));
    Enumeration enumeration = jarFile.entries();
    while(enumeration.hasMoreElements()){
    String className = ((ZipEntry)enumeration.nextElement()).getName();
    if(className.endsWith(".class")){
    className = className.substring(0, className.length()-6);
    if(className.indexOf("Driver")!=-1)System.out.println(className);
    try{
    Class classe = loadClass(className, true);
    Class[] interfaces = classe.getInterfaces();
    for(int i=0; i<interfaces.length; i++){
    if(interfaces.getName().equals("java.sql.Driver")){
    drivers.add(classe);
    Class superclasse = classe.getSuperclass();
    interfaces = superclasse.getInterfaces();
    for(int i=0; i<interfaces.length; i++){
    if(interfaces[i].getName().equals("java.sql.Driver")){
    drivers.add(classe);
    }catch(NoClassDefFoundError e){
    }catch(Exception e){}
    public Enumeration getDrivers(){
    return drivers.elements();
    public String getJarFileName(){
    return jarFile.getName();
    public static void main(String[] args) throws Exception{
    DriverFinder df = new DriverFinder("D:/Classes/db2java.zip");
    System.out.println("jar: " + df.getJarFileName());
    Enumeration enumeration = df.getDrivers();
    while(enumeration.hasMoreElements()){
    Class classe = (Class)enumeration.nextElement();
    System.out.println(classe.getName());
    It loads a jar and searches it looking for drivers (classes implementing directly or indirectly interface java.sql.Driver) At the end of the execution I have found all drivers in the jar file.
    The main application loads jar files from an XML file and instantiates one DriverFinder for each jar file. The problem is at execution time, it finds the drivers and i think loads it by issuing this statement (Class classe = loadClass(className, true);), but what i think is not what is happening... the execution of my code throws this exception
    java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:140)
    at com.marmots.database.DB.<init>(DB.java:44)
    at com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
    at com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
    at com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
    at com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
    Driver file is not in the classpath !!!
    I have tried also (as you can see in comented lines) to update System property java.class.path by adding the path to the jar but neither...
    I'm sure I'm making a/some mistake/s... can you help me?
    Thanks in advice,
    (if there is some incorrect word or expression excuse me)

  • Images in a JAR file

    Hi all,
    I need see by code all the names of the resources (Images) that are includes into a JAR file. There are some function that do that work?.
    Thanks in advance!!
    Salvador Huertas.

    For example          /* test.jar is a jar file containing some files, one directory named traffic
                 and some files in the traffic directory. */
              JarFile jf = new JarFile("test.jar");
              Enumeration enum = jf.entries();
              ArrayList list = new ArrayList();
              while(enum.hasMoreElements()) {
                   String s = enum.nextElement().toString();
                   if(s.indexOf("traffic/") > -1 && s.length() > "traffic/".length()) list.add(s);
              System.out.println(list); //Displays the files in the traffic directory

  • Read filenames from jar-file

    Hi,
    I want to read image names in a jar-file directory in a web start application. This used to work in previous versions of jdk,
    but when I use jdk 1.6.0_20 I get this errormessage:
    "http:\server:8080\test\client.jar The filename, directory name, or volume label syntax is incorrect".
    Why doesn´t this work anymore?
    Some of my code looks like this:
         getFiles("images/toolbuttons/val/", ".gif", true);
         public String[] getFiles(String catalog, String fileNameEnd,
             boolean removePath)
              JarFileFinder jarFileFinder = new JarFileFinder();
              String jarFilePath = jarFileFinder.getClassLocation(
                  this.getClass().getName());
              String[] files = null;
              try
                   if (fileNameEnd != null)
                        fileNameEndFilter = new FileNameEndFilter(fileNameEnd);
                   files = getFilesInJar(jarFilePath, fileNameEndFilter, catalog,
                       removePath);
              catch (Exception e)
                   MessageUtil.messageOk(null, this.getClass().getName(), e.getMessage());
              return files;
         private String[] getFilesInJar(String jarFilePath, FilenameFilter filter,
             String catalog, boolean removePath)
             throws Exception
              ZipFile zipFile = new ZipFile(jarFilePath);
              Enumeration e = zipFile.entries();
              String name;
              ZipEntry zipEntry;
              ArrayList filesList = new ArrayList();
              while (e.hasMoreElements())
                   zipEntry = (ZipEntry) e.nextElement();
                   name = zipEntry.getName();
                   if ((filter == null || !filter.accept(null, name)) ||
                       (catalog != null && !name.startsWith(catalog)))
                        continue;
                   if (removePath == true)
                        name = name.substring(name.lastIndexOf("/") + 1);
                   filesList.add(name);
              String[] files = new String[filesList.size()];
              for (int i = 0; i < filesList.size(); i++)
                   String s = (String) filesList.get(i);
                   files[i] = s;
              return files;
    public class JarFileFinder
         public String getClassLocation(String classname)
              try
                   Class clazz = Class.forName(classname);
                   if (clazz == null) return null;
                   URL url =
                       clazz.getProtectionDomain().getCodeSource().getLocation();
                   String location = url.toString();
                   if (location.startsWith("jar"))
                        url = ((JarURLConnection)
                            url.openConnection()).getJarFileURL();
                        location = url.toString();
                   if (location.startsWith("file"))
                        return new File(URLDecoder.decode(url.getFile(), "UTF-8")).getAbsolutePath();
                   else
                        return URLDecoder.decode(url.toString(), "UTF-8");
              catch (Exception e)
                   MessageUtil.messageOk(null, this.getClass().getName(), e.getMessage());
              return null;
    }

    AndrewThompson64 wrote:
    Lisa_R wrote:
    ..I tried to remove the URLDecoder, but the result was the same. I still get:
    "http:\server:8080\test\client.jar The filename, directory name, or volume label syntax is incorrect".Given an URL should use '/' as opposed to '\', and starts with 2 '/' rather than one, it is not surprising that URL was rejected. Strange as it may seem, programming by typing random characters into an editor will rarely, if ever, work to create a working application.Yes, I agre that it´s not that surprising that the URL was rejected (even though the URL work in firefox and IE). But I didn´t write it that way. The code that put the URL together worked fine in previous versions of the jdk.
    >
    ..The reason why I want to read the filenames from the jar instead of including a list of the names is that if you
    want to add an image then all you have to do is include it in the directory.. That is largely irrelevant, since the Jar needs to be freshly built, uploaded by the developer, and downloaded by the client. Since all of that needs to be done for the addition of a single image, you might as well add an Ant task to the build that provides a single file (like I suggested earlier) that lists the resources of interest. It would take less time to write an Ant task, than debug all the hoops the code is currently jumping through(1) in order to get the information of interest.
    If this was the only place were this method was used I would agre with you, but unfortunatelly it´s not. The application dosen´t only read image filenames it also reads class-names.
    1) And even if you got that working, it would be likely that Sun would introduce some change in the next version of Java that breaks it again. My advice is to stop fighting it, and go with the flow.Thats not good of course! But it has been working for a long time, so I think I will try to make it work again....
    Is there someone out there who has done this or knows how to do it I would appreciate some help! :-)

  • Find a class under Jar file

    Hi all,
    If I want to find out a class resides under what jar file, under Linux, I use this command:
    for i in $(find -name \*.jar) ; do if jar tf $i | grep �q className.class ; then echo $i ; fi ; done
    Does anybody know how can I do this under Windows? If I need to know a class is under what jar file, is there anyway to do this except extracting each jar file and see what classes are under the jar file?
    Is there any tool that can mount the jar file and expand it in a tree structure to see all of it's classes visually?
    Any help is greatly appreciated.

    if you have a lot of jars, its actually time-consuming....Sorry, my computer freez.
    Vector<String> parcalar=null;
              try {
              JarFile jarfile = new JarFile(new File("lang.jar"));
              Enumeration<JarEntry> dosyalar=jarfile.entries();
              parcalar=new Vector<String>();
              System.out.println(jarfile.size()-2);
              while(dosyalar.hasMoreElements()) {
                   JarEntry entry = dosyalar.nextElement();
                   String name=entry.getName();
                   if(name.equals("MessagesBundle.properties")) {
                        //parcalar="--------------------";
                   else if(name.equals("META-INF/MANIFEST.MF")) {
                   else {
                        parcalar.addElement(name);
              catch(IOException ex){
                   ex.printStackTrace();
    System.out.println(parcalar);

  • Loading icons from jar file

    Hello,
    i am trying to load ALL imagefiles from my jar file. i do the following:
    Class clazz = Class.forName("com.xxx.IconSelectionDialog");
    String me = clazz.getName().replace(".", "/") + ".class";
    dirURL = clazz.getClassLoader().getResource(me);
    if (dirURL.getProtocol().equals("jar")) {
    String jarPath = dirURL.getPath().substring(6, dirURL.getPath().indexOf("!")); //strip out only the JAR file
    JarFile jar = new JarFile(jarPath );
    Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
    while (entries.hasMoreElements()) {
    JarEntry nextEntry = entries.nextElement();
    String jarEntryName = nextEntry.getName();
    this works fine with my debug local jws installation. when i try to run it online starting i get an error:
    java.io.FileNotFoundException: xentis.jar (Das System kann die angegebene Datei nicht finden)
         at java.util.zip.ZipFile.open(Native Method)
         at java.util.zip.ZipFile.<init>(ZipFile.java:114)
         at java.util.jar.JarFile.<init>(JarFile.java:133)
         at java.util.jar.JarFile.<init>(JarFile.java:70)
    how can i load ALL icons from a jar (without knowing the filename) ?
    is there a generic way to iterate over all entries of a jarfile ?
    thank you
    michael

    Look at "Loading Images Using getResource" on this page
    http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
    It should provide some ideas.

  • Making jar files using API

    hello!
    I m trying to make a jar file using the API. When the jar tool is used for the same manifest file, it is correctly written and an executable jar is created. When I use the API, the jar file is made but it is nor executable. Here is that part of code:
    jar = new File(parent, jarName);
    System.out.println("Executing jar command...");
    //create jar file here
    Manifest mf = new Manifest(new FileInputStream(manifest));
    fos = new FileOutputStream(jar);
    jos = new JarOutputStream(new BufferedOutputStream(fos), mf);
    BufferedInputStream reader = null;
    byte[] data = new byte[BUFFER];
    int byteCount = 0;
    for(int i = 0; i < fileNames.length; i++)
    System.out.println("Adding " + fileNames);
    FileInputStream fis = new FileInputStream(fileNames);
    reader = new BufferedInputStream(fis, BUFFER);
    JarEntry entry = new JarEntry(new ZipEntry(fileNames));
    jos.putNextEntry(entry);
    while((byteCount = reader.read(data,0,BUFFER)) != -1)
    jos.write(data, 0, byteCount);
    }//end while
    reader.close();
    }//end for
    jos.close();//close jar output stream
    fos.close();
    I m sure someone will be kind and intelligent enough to solve the problem. Thank you!
    Umer

    A jar file is simply a Zip file. So the two API's are quite similar. First, you create a CRC - that is a way to make sure that the file isn't corrupted and that all the bytes are there (it's a polynominal algorithm that returns a number which is written in the Zip(Jar) file as well). Each entry is a file or directory. Before writing any data to the Zip(Jar) file, you have to write info on the actual file (like name, path, length etc). That's why you use putNextEntry(). Each file can have it's storing methods, although the most common is to use the "default" methods (built in the ZipOutputStream/JarOutputStream)
    But in this example you set the storing methods on the entry. You use the setMethod() method to switch between either storing or compression (don't know why, but in this example you don't compress the file - you should). I myself don't use the setSize() and setCompressedSize() methods at all (and it works fine). Don't know exactly what are the implications of using them. Neither do I use the setCrc() method (If I think a little, I've only used this API once - I don't use it that much), but it's quite straightforward. It's used to check that the data is ok, and since the CRC number is the result of an algorithm, it needs to know the bytes of UNCOMPRESSED data: that's why you use crc.update() on the bytes. After that you actually write all the info set before to the Zip (Jar) file using putNextEntry(). But remember that a ZipEntry doesn't have any data. You'll have to write it yourself: thus the need for the write method: Here are two small programs I used for Zipping and Unzipping. Changing them to work for Jar files is extremely simple:
    //Zip.java
    import java.io.*;
    import java.util.zip.*;
    public class Zip
         public static void main(String[] arg)
              try
                   if (arg.length < 3)
                        System.out.println("Usage: java Zip <0-9> <zip file> <file 1> [file 2] [file 3] ...");
                        System.exit(0);
                   System.out.println("Compressing files into file " + arg[1]);
                   ZipOutputStream out = null;
                   try
                        out = new ZipOutputStream(new FileOutputStream(arg[1]));
                   catch (FileNotFoundException ex)
                        System.out.println("Cannot create file " + arg[1]);
                        System.exit(1);
                   try
                        out.setLevel(Integer.parseInt(arg[0]));
                   catch (IllegalArgumentException ex)
                        System.out.println("Illegal compression level");
                        new File(arg[1]).delete();
                        System.exit(1);
                   for (int i=2; i<arg.length; i++)
                        System.out.println("\tCompressing file " + (i-1));
                        FileInputStream read = null;
                        try
                             read = new FileInputStream(arg);
                        catch (FileNotFoundException ex)
                             System.out.println("\tCannot find file " + arg[i]);
                             continue;
                        out.putNextEntry(new ZipEntry(arg[i]));
                        int av = 0;
                        while ((av = read.available()) != 0)
                             byte[] b = new byte[av < 64 ? av : 64];
                             read.read(b);
                             out.write(b);
                        out.closeEntry();
                        read.close();
                        System.out.println("\tDone compressing file " + i);
                   System.out.println("Done compressing");
                   out.finish();
                   out.close();
              catch (Exception e)
                   new File(arg[1]).delete();
                   e.printStackTrace(System.err);
    And the unzipping app:
    //UnZip.java
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    public class UnZip
         public static void main(String[] arg)
              try
                   if (arg.length < 1)
                        System.out.println("Usage: java UnZip <zip file> [to dir]");
                        System.exit(0);
                   String dir = "";
                   if (arg.length > 1)
                        dir = arg[1] + System.getProperty("file.separator");
                        File f = new File(arg[1]);
                        if (!f.exists()) f.mkdirs();
                   System.out.println("Decompressing files from file " + arg[0]);
                   ZipFile read = null;
                   try
                        read = new ZipFile(arg[0]);
                   catch (ZipException ex)
                        System.err.println("Zip error when reading file " + arg[0]);
                        System.exit(1);
                   catch (IOException ex)
                        System.err.println("I/O Exception when reading file " + arg[0]);
                        System.exit(1);
                   Enumeration en = read.entries();
                   while (en.hasMoreElements())
                        ZipEntry entry = (ZipEntry) en.nextElement();
                        System.out.println("\tDecompressing file " + entry.getName());
                        FileOutputStream out;
                        try
                             out = new FileOutputStream(dir + entry.getName());
                        catch (FileNotFoundException ex)
                             System.err.println("\tCannot write down to file " + dir + entry.getName());
                             continue;
                        InputStream re = read.getInputStream(entry);
                        int nRead = 0;
                        for (byte[] buffer = new byte[1024]; (nRead = re.read(buffer)) != -1; out.write(buffer, 0, nRead));
                        out.close();
                        System.out.println("\tDone decompressing file " + entry.getName());
                   read.close();
                   System.out.println("Done decompressing files");
              catch (Exception e)
                   new File(arg[1]).delete();
                   e.printStackTrace(System.err);

Maybe you are looking for

  • BAPI for post Tax Amount

    Hi, Please tell me BAPI for post Tax Amount. Which tcode use for Post tax code, is it FB01 or FB60. Regards Jana

  • Data Package 1 : arrived in BW ; Processing : Selected number does not agre

    Hi experts, When loading data into PSA via UD Connect, getting the following error: Overall status: Errors occurred: or: missing messages   - (red light) Requests (messages): Everything OK  - (green light)    Data request arranged - (green light)   

  • CP File Won't Open

    I'm having a similar problem to others I've seen posted. Just created a cp file and can't open it. When you double-click the file, Captivate launches but only goes to the opening screen. You can see the slides from this file when you try to import it

  • Problem viewing data in Performance monitroing in RWB

    hi Forum, In RWB in "Performance Monitoring", When i try to display "Overview Aggregated/Overview individually/Detailed Data Aggregated/Detailed Data individually", i am unable to view data before 07-june-2010 (for information today's date is 22 June

  • Rendered sequence video is flipped vertically, dimmed and b&w

    Hi community!  I searched, but all instances I found of similar behavior were either on much older versions or else had unique circumstances... I keep seeing odd behavior of my footage in the timeline.  All of my clips begin in AE CS6, which I then e