When I create a jar I do the following:
*.java
files that belong in the packagejar cf anyName.jar packageName/*
I can then delete the folder I created for the package as I'm left with the jar in the working directory.
My question: Why does the folder name need to be the package name?
When you create a jar file by default it stores the relative path of the files specified by the command line arguments/patterns.
And you need to store a file was with the folder structure corresponding to package names. There's only one-to-one match between the Java package name and the folder structure.
The basic knowlage about packages in the Java Tutorial:
A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.
For more information how to use jar command to create jar files see the Java tutorial.
The basic format of the command for creating a JAR file is:
jar cf jar-file input-file(s)
The options and arguments used in this command are:
- The
c
option indicates that you want to create a JAR file.- The
f
option indicates that you want the output to go to a file rather than to stdout.jar-file
is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required.- The
input-file
(s) argument is a space-separated list of one or more files that you want to include in your JAR file. Theinput-file
(s) argument can contain the wildcard*
symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.