5 Replies Latest reply: Apr 29, 2011 1:41 PM by 796440 RSS

    Adding multiple files to jar with wildcard symbol *

    488425
      Hello

      It looks like that the "jar" command has problems with the wildcard symbol *

      Here is an example


      THIS DOESN'T WORK (multiple pdf's):
      "D:\Program Files\Java\jdk1.6.0_17\bin\jar" cf OfflineDocs.jar -C "D:\Program Files\Tomcat\webapps\toplife\applets\help" \avb_d\WebHelp\*.pdf

      THIS WORKS (1 pdf):
      "D:\Program Files\Java\jdk1.6.0_17\bin\jar" cf OfflineDocs.jar -C "D:\Program Files\Tomcat\webapps\toplife\applets\help" \avb_d\WebHelp\EAB001D.pdf

      Any ideas?
      Thanks for your help
        • 1. Re: Adding multiple files to jar with wildcard symbol *
          796440
          Like most programs, jar doesn't expand the asterisk. The shell does that. That's why
          jar cf foo.jar *.class
          works, because the shell turns *.class into a.class b.class c.class, which is what the jar program sees.

          That doesn't work with -C, because the shell doesn't know about the -C, so it tries to expand *.class in the current directory. If I have x.class and y.class in the current directory, and a.class, b.class, and c.class in the directory where I want jar to cd to, I might try what you did:
          jar -cf foo.jar -C /tmp *.class
          thinking that I'd get /tmp's a, b, and c.class files. However, the shell expands that to
          jar -cf foo.jar -C /tmp x.class y.class
          In short, you can't use the asterisk with the -C option (unless you happen to have files with the same names in your current directory).
          • 2. Re: Adding multiple files to jar with wildcard symbol *
            488425
            Hello. Thanks for your answer.

            A friend of mine used this:

            D:\Java\j2sdk1.4.2_09\bin\jar cf OfflineDocs.jar -C \Web\Tomcat\webapps\toplife\applets\help \Web\Tomcat\webapps\toplife\applets\help\avb_d\WebHelp\*.pdf

            and it works!

            The only difference I see is the path (in my case with a space and "").
            • 3. Re: Adding multiple files to jar with wildcard symbol *
              796440
              user485422 wrote:
              Hello. Thanks for your answer.

              A friend of mine used this:

              D:\Java\j2sdk1.4.2_09\bin\jar cf OfflineDocs.jar -C \Web\Tomcat\webapps\toplife\applets\help \Web\Tomcat\webapps\toplife\applets\help\avb_d\WebHelp\*.pdf

              and it works!

              The only difference I see is the path (in my case with a space and "").
              Yeah, but that defeats the purpose of the -C. You use -C so that you can give relative paths, and they will appear as such in the jar.

              If you do jar tvf OfflineDocs.jar, you see the full paths, starting with \Web, right? That means you could have completely skipped the -C \Web\... part.
              • 4. Re: Adding multiple files to jar with wildcard symbol *
                488425
                The structure in the jar is:

                avb_d\WebHelp\*.pdf

                Edited by: user485422 on 29.04.2011 08:52

                Edited by: user485422 on 29.04.2011 08:54
                • 5. Re: Adding multiple files to jar with wildcard symbol *
                  796440
                  user485422 wrote:
                  The structure in the jar is:

                  avb_d\WebHelp\*.pdf
                  That's rather surprising. It tried something like that earlier and I didn't get those results. I'll try to do some more messing around later and see what I come up with. It might have to do with a Windows vs. Linux vs. Cygwin difference in how that * is expanded.

                  Edited by: jverd on Apr 29, 2011 11:41 AM