blavi
blavi

Reputation: 531

How to make a jar file without recording the directory name?

The folder Test contains various files and folders. I want to create a jar that contains only the Test's sub-folders and files, without the directory's name (Test) in hierarchy.

I've tried:

 ProcessBuilder createJarProcess2 = new ProcessBuilder("jar", "cMf", "test.jar","test");
 p = createJarProcess2.start();
 stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
 // read any errors from the attempted command
 while ((s = stdError.readLine()) != null) {
       System.out.println(s);
 }
 p.waitFor();
 System.out.println("create jar 2  " + p.exitValue());

But includes also the directory's name.

Thanks

Upvotes: 3

Views: 3970

Answers (1)

user166390
user166390

Reputation:

See the -C option:

Temporarily changes directories to dir while processing the following inputfiles argument. Multiple -C dir inputfiles sets are allowed.

Example:

jar cMf test.jar -C Test .

Happy coding.

Upvotes: 11

Related Questions