Re: Need help linking & packages



Doug Robinson <dkrqXXX@xxxxxxxxxxxxxxxxxx> wrote:
If I try to access another jar files default package I have no

With the exception of "sealed packages", jars and packages are unrelated.
Jars can contain classes from multiple packagages, and classes in the same
package can live in multiple jars.

There is no "default package" for a jar. There is the or un-named package
that can have classes in it, but generally you shouldn't use it as it's a PITA
to mix named and un-named packages.

package a.b.c.*;

* isn't a valid package name for this class.

import Another.*;

This will make short names used in java code search the Another package for a
match. It's just a coding shortcut, and has no effect at runtime (it
doesn't even end up in your .class file). Since you have no java references
to any class, it will have no effect.

Oh, and by convention packages should start with lower-case letters. Classes
start with a capital. And it does matter - names are case-sensitive.

class Test {
System.out.println ("Hello World");
try {
Class.forName("another/Thing");

Class names don't have slashes in them. They have dots to separate package
elements and to separate package from classname. Packages and classes are
case-sensitive, too, so "Another" and "another" are different. Try
Class.forName("another.Thing"). Since this is a method call rather than java
code to be compiled, the imports have no effect and you must pass in the
fully-qualified classname.

But really, there's no reason to do this for most programs. Class.forName()
is only needed if you don't know when writing the code what the class name
will be.

You should just do:
Thing t = new Thing();
/* or whatever. If you haven't imported another.* or another.Thing,
you can say another.Thing t = new another.Thing(); */

// Class.forName("Stuff");

This is an example of trying to use the unnamed package to look for Stuff.
Getting that to work is unfortunately complicated, and you should just avoid
having classes without a specified package name.

Good luck!
--
Mark Rafn dagon@xxxxxxxxx <http://www.dagon.net/>
.



Relevant Pages

  • Re: Adding some Penzance into the cellar
    ... jars. ... I put the tobacco in 2 oz. ... remove the jars and lids with tongs and put the tobacco in while still ... some "aged" Stonehaven left in the package (in the same type of package ...
    (alt.smokers.pipes)
  • Re: How do you execute a JAR file?
    ... java -jar GUI.jar ... Knute Johnson ... remains unnamed by NetBeans, however, when it "jars" up the Main-Class becomes "GUI.IconMaker". ... You need to put it all in the default package or IconMaker needs to be in the GUI package. ...
    (comp.lang.java.help)
  • Re: Adding some Penzance into the cellar
    ... jars. ... When I get Penzance or Stonehaven and pretty much anything that is in a foil sealed wrap, I put the tobacco in 2 oz. ... I always put the jars and lids into a large pot with a steamer inside and let them sit in a covered pot at a steady boil for around 20 minutes or so. ... I've had the misfortune of using some "aged" Stonehaven left in the package that was quite old but not aged in a good way: simply dry and nearly without flavor. ...
    (alt.smokers.pipes)
  • Re: Adding some Penzance into the cellar
    ... jars. ... I put the tobacco in 2 oz. ... remove the jars and lids with tongs and put the tobacco in while still ... some "aged" Stonehaven left in the package (in the same type of package ...
    (alt.smokers.pipes)
  • Re: references on all Java classes within the same package
    ... You can use the current classpath to open all Jars and all ... which would also include the system class loader. ... most part after doing all that, you could get all classes in a package. ...
    (comp.lang.java.programmer)