简体   繁体   中英

How to JAR files using relative path of root directory?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM