Is there a way to create a jar from a directory with Python?

I want to generate a jar in a Python script with assets that are dynamically generated and .class files.

Could I just create a .zip file and rename the file extension?


Yes, you can just create a ZIP file and rename the extension. It’s that easy.

Do keep in mind that you might want to add (beside your class files) some metadata related files of a JAR (Java Archive), such as: