>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@dagon.net <http://www.dagon.net/>
Doug Robinson - 15 Aug 2007 17:06 GMT
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.
Thank you for your response!
I am well aware of all of the things you say. but but but...
The recomended way to "connect" to say a jdbc driver is indeed
Class.forName("driver.package...");
and in no way was I recommending the use of the "unnamed package" just
that I CAN "connect" to jars that contain one.
However I still can not make any reference to a "package" work in this
fashion.
Thanks again for your time & effort!
dkr
Mark Rafn - 15 Aug 2007 18:17 GMT
>Thank you for your response!
>I am well aware of all of the things you say. but but but...
>The recomended way to "connect" to say a jdbc driver is indeed
>Class.forName("driver.package...");
Ah, yes. JDBC driver loading involves certain tricks where a driver registers
itself when the classloader first loads the class. Knowing you're having
troubles with JDBC rather than general java package questions is helpful.
>However I still can not make any reference to a "package" work in this
>fashion.
Then it's time to get specific. Show us a small self-contained example, and
the output you get when you run it. A single class with a main(String[]) that
loads the driver should be sufficient.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>