Caffeinated
Caffeinated

Reputation: 12484

What's the difference between the following two ways to create an executable JAR?

I was reading up on how-to create a jar file in java , so the way is like this :

jar cmf mainclass.txt example.jar *.class

I was curious about why we use *.class rather than specifically saying something like example.class ? I have a directory with many class files, how would it know which one to use? Here is how my directory looks. thanks!

EDIT: Thanks a lot I created a new directory and this saved my about 50% bytes!

Upvotes: 1

Views: 83

Answers (3)

scgr
scgr

Reputation: 57

The .jar file need only the .class needed

EDIT: In this case, the * include all .class files.

Upvotes: 1

Brian Roach
Brian Roach

Reputation: 76918

* is simply a wildcard for the shell and expands to match all the files that end with .class in the current directory.

If you don't want that ... instead you would list the specific .class files you want to add.

Typically you use *.class because often the .class files in a directory make up a project, and thus all of them are needed in the .jar.

Upvotes: 3

Jit B
Jit B

Reputation: 1246

specifying *.class will include all the files with .class extension. You should use this only when you know that you need all the .class files in your jar

Upvotes: 1

Related Questions