Doug Robinson <dk*****@XXXtel usplanet.netwro te:
>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.prin tln ("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
da***@dagon.net <http://www.dagon.net/>