I have a folder structures
/com/cdy/ws/a.class files /com/cdy/ws/b.class files /com/cdy/ws/c.class files
When I run the following command “jar cvf asd.jar *.class” it gives jar with all the class files. But the folder structure is not getting generated. All the class files have to be under “com.cdy/ws” but all the classes are in same level of META-INF. Can anyone tell me what is the command to generate the package structure?
Thanks
How to create a runnable jar file from multiple java packages. Example java main method file. Lets first compile to java byte-code. Now we are ready to compile / create the jar file.
A JAR (Java ARchive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.)
You need to start creating the JAR at the root of the files.
So, for instance:
jar cvf program.jar -C path/to/classes .
That assumes that path/to/classes
contains the com
directory.
FYI, these days it is relatively uncommon for most people to use the jar
command directly, as they will use a build tool such as Ant or Maven to take care of that (and other aspects of the build). It is well worth the effort of allowing one of those tools to take care of all aspects of your build, and it's even easier with a good IDE to help write the build.xml
(Ant) or pom.xml
(Maven).
You want
$ jar cvf asd.jar .
to specify the directory (e.g. .
) to jar
from. That will maintain your folder structure within the jar file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With