I have a jar file and I have a path which represents a location inside Jar file.
Using this location I need to replace class file inside jar(Add a class file in some cases).I have class file inside another folder which is present where jar is present(This class file i have to move to Jar).
Code which I am trying to achieve above objective :
import zipfile
import os
zf = zipfile.ZipFile(os.path.normpath('D:\mystuff\test.jar'),mode='a')
try:
print('adding testclass.class')
zf.write(os.path.normpath('D:\mystuff\testclass.class'))
finally:
print('closing')
zf.close()
After executing above code when I saw jar below mentioned format:
Jar
|----META-INF
|----com.XYZ
|----Mystuff
|--testclass.class
Actual Output I need is -
Jar
|----META-INF
|----com.XYZ
|--ABC
|-testclass.class
How can achieve this using zipfile.write command or any other way in python?
I didn't find any params in write command where i can provide destination file location inside Jar/Zip file.
ZipFile.write(filename, arcname=None, compress_type=None)