Dan Stromberg wrote:
What's the relationship between jar files, package statements and import?
Specifically, what do I need to put into a .java that goes into a jar
that has just an interface, in order to be able to import just the
interface in another .java and build against that interface?
Could someone please post a concise example?
Could someone please provide a pithy list of steps like that for java,
including the object orientation and (the separation of interface and
implementation) and the jar creation?
Let's say your interface is in the source tree /ifacesrc/, and that the
implementation is in /implsrc/, and that the implementation has an
appropriate main() method.
cd /ifacesrc/
javac foo/bar/baz/if/TheInterface.java
jar cf iface.jar foo/bar/baz/if/TheInterface.class
plus a bunch of manifest steps best followed from the instructions at Sun:
<http://java.sun.com/javase/6/docs/technotes/tools/index.html>
<http://java.sun.com/javase/6/docs/technotes/tools/solaris/jar.html>
cd /implsrc/
javac -cp .:/ifacesrc/iface.jar foo/bar/baz/Implementation.java
javac -cp .:/ifacesrc/iface.jar foo.bar.baz.Implementation
You might want to review the information about CLASSPATH and related
issues:
<http://java.sun.com/docs/books/tutorial/essential/environment/paths.html>
<http://java.sun.com/javase/6/docs/technotes/tools/findingclasses.html>
The import statement, of course, is optional. You can always refer to classes
by their fully-qualified names (FQNs).