Re: Abstraction layers in C++ and in Java
James Kanze said:
CLASSPATH is provided by the invoker, not by you. You have very
little control over what he provides.
That is wrong. I suppose you are thinking in the CLASSPATH environment
variable which may be set in a user enviroment. When you provide a
java [sic] program, you also provide the way to launch it (for exemplio a batch
file) in which you specify the classpath *you* want. Put the classpath
to libraries bundled with your binaries, and you be sure your program
The standard way to package a Java standalone application is in a JAR file, in
which the manifest specifies the classpath in terms of affiliated JARs,
unpacked with the application JAR in the same installation directory or
subdirectories thereof. The invoker's CLASSPATH is explicitly ignored when
the application runs with the "java -jar" option.
The trouble with a "batch file" (i.e., a shell script) is that it defeats the
portability of Java, presumably one of the reasons to use Java in the first
place. The "-jar" option is as portable as Java itself. It obviates the
dependency on the CLASSPATH envar and on the OS shell, and provides an
alternative that can be deployed with the application itself.
How do you control which JRE your user uses? Do you bundle that as well?
No, silly. You inform the user of the minimum system requirements for your
product, just like everyone else does. You don't buy them a computer, either.
Java WebStart makes it convenient to script the requirement, and to give the
user an opportunity to upgrade their Java if need be.