0

How to use JarOutputStream to create a JAR file?

Using that solution causes creating entry with absolute path in *.jar file, for example c:/Users/foo/Temp/blah/com/example/Main.class. I want to build jar with path relative to root, in this example it will be c:/Users/foo/Temp/blah and entries should be com/example/... How to achieve that? Changing working directory is strongly platform-dependent, so it's not good solution.

PS. I've replaced Windows's backslash with slash.

Marcin Las
  • 33
  • 1
  • 7

1 Answers1

2

The 'path' is actually whatever name you set into each JarEntry when creating it. Just calculate the relative path yourself and use that for the name parameter when calling the JarEntry constructor.

jingx
  • 3,698
  • 3
  • 24
  • 40