Reputation: 55
I am trying to create .jar files in java which can be used by including it in other projects. It doesn't contain any main but only classes and methods. I am using th following command to create .jar file from command line
jar cf firstjar.jar *
I am including the jar file in my project but still the class is not available in the project. What's the problem in this.
Upvotes: 0
Views: 1312
Reputation: 1502616
My guess is that you've got a problem with the directory structure.
Suppose you have a class like this:
package org.foo;
public class Bar {}
There should be Bar.class
flie in a directory org/foo
. That structure has to be in the jar file as well - so you should go to the directory containing org
and run:
jar cf firstjar.jar org
(Or whatever your top-level package name is.)
If you just include the classfiles from the foo
directory then Java's expectations of where to find things will be invalid.
Upvotes: 1