jar -C option does not seem to work

jar, java

Solution

You seem to be confused with the command line options. The usage is:

Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...

-C  change to the specified directory and include the following file

(Notice include the following file in the help for `-C` option.) When you say:

jar cvf a.jar -C ../bin/ ../bin/a.class ../bin/b.class

it looks for `../bin/../bin/a.class` and `../bin/b.class` which results into the behavior that you observe. Either say:

jar cvf a.jar ../bin/a.class ../bin/b.class

or

jar cvf a.jar -C ../bin/ a.class -C ../bin/ ../bin/b.class

For including all the files in the `../bin/` directory, say:

jar cvf a.jar -C ../bin/ .

Problem

I am using the command ``` $ jar cvf a.jar -C ../bin/ ../bin/a.class ../bin/b.class ``` the output is: ``` adding: ../bin/a.class(in = 0) (out= 0)(stored 0%) adding: b.class(in = 0) (out= 0)(stored 0%) ``` The -C option does not work for the first file but works for the second. What can be the problem?

Original source