Image of How to create a jar file with a package structure

ADVERTISEMENT

Table of Contents

Introduction

This tutorial allows you to archive a list of compiled classes residing under a particular package in the form of a JAR file.

Suppose you have 2 classes A.class & B.class which resides under com.programmer.gate. In order to export a JAR file out of these 2 classes without losing the package route, you must do the following:

  1. Go the root folder of the package, in our case it’s com.
  2. Press shift and right-click, then open cmd.
  3. Run this command: jar cvf test.jar .
  4. The dot(.) used at the end of the above command informs the jar operation to package the classes starting from the current path.
  5. After running the command, you will get a jar file called test.jar besides the com folder.

Summary

This tutorial allows you to archive a list of compiled classes residing under a particular package in the form of a JAR file.

Next Steps

If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.

Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to jacob@initialcommit.io.

Final Notes