Re: Accessing .class files in a Jar
Redbeard wrote:
Can this be done?
I am in an educational setting where students will need some class
files that I have created to make a project work. They need to be able
to download the files via the internet, so I cannot Jar them up and
preinstall them in the ext directory. And I cannot be certain that
they could accomplish that themselves.
Right now, they will have to download the files individually and place
them in the same directory that they will create their project in.
Assuming that they don't miss a file, that WILL work.
This will only work if the class files they download belong to the same package
as the class files they are creating for themselves. That seems very unlikely
to me, unless you and the students are both using the "default" package, and
that's probably not a good idea.
But I'd like to be able to Jar them up and just let the students
download the one Jar file into that directory and access the files
stored there.
They can do that, provided you build your jar correctly. You need to ensure that
the filesystem within the jar matches the package structure of the class files.
Then the students will need to use the correct import statements to access your
classes, and reference the jar in the classpath both for compilation and for
execution.
I've experimented with this without success. Before I waste too much
time on it, I figured it would make sense to see if anyone knows if it
can even be done.
Certainly it can be done. That's how Java works, installing jar files downloaded
from the net is in essense what you do when you install the Java SDK/JRE. One
of the strengths of Java is that it's so easy to incorporate existing jars into
your own applications.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555