Re: jar, package and import relationship?
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Wed, 09 Jan 2008 22:01:19 -0500
Lew wrote:
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>
Part 2: package
Interface:
package foo.bar.baz.if;
Implementation:
package foo.bar.baz;
import foo.bar.baz.if.TheInterface;
The import statement, of course, is optional. You can always refer to classes by their fully-qualified names (FQNs).
--
Lew
.
- References:
- jar, package and import relationship?
- From: Dan Stromberg
- Re: jar, package and import relationship?
- From: Lew
- jar, package and import relationship?
- Prev by Date: Re: Great SWT Program
- Next by Date: Re: Great SWT Program
- Previous by thread: Re: jar, package and import relationship?
- Next by thread: Re: jar, package and import relationship?
- Index(es):
Relevant Pages
|