classpath and jarfile question

  • Thread starter Martin Gregorie
  • Start date
M

Martin Gregorie

I have a problem with class path behavior when trying to run an app from
within a jar file. The app depends on other jar files, e.g. JDBC driver,
JavaMail, that are not part of the standard distribution.

The manifest sets Start-Class. If I also add Class-Path: to the manifest
with a copy of $CLASSPATH as its argument (':' replaced with space)
Start-Class set the application runs with the command:

"java -jar jarfile.jar arguments...."

but if I remove the Class-Path from the manifest I can't get the
application to run from the jar file regardless of whether I let the
class path default to $CLASSPATH or supply it explicitly to the java via
the -classpath option. I'd prefer not to specify the class path in the
manifest because I can't guarantee that the required support jar files
will be in the same place on other systems.

The jar file is in the same directory as the collection of *.class
files. Running "jar StartClass arguments..." works just fine, so there's
nothing wrong with $CLASSPATH. The class files form an application suite
rather than a library and so are not part of a package.

As I understand the definition of the manifest and class path behavior,
if there is no "Class-Path:" parameter in the manifest the class path
should default to the class path given by -classpath or, if that's
absent, to $CLASSPATH. What have I misunderstood?


TIA,
Martin
 
L

Lew

Martin said:
"java -jar jarfile.jar arguments...."
As I understand the definition of the manifest and class path behavior,
if there is no "Class-Path:" parameter in the manifest the class path
should default to the class path given by -classpath or, if that's
absent, to $CLASSPATH. What have I misunderstood?

That the external class path is ignored when you invoke "java -jar".
-jar
Execute a program encapsulated in a JAR file. ....
When you use this option, the JAR file is the source of all user classes,
and other user class path settings are ignored.
<http://java.sun.com/javase/6/docs/technotes/tools/solaris/java.html>

Use the manifest. Distribute the JARs with the app.
 
M

Martin Gregorie

Lew said:
That the external class path is ignored when you invoke "java -jar".
Thanks. I was reading the "jar' manual in the SDK Documentation tree and
found its description of Class-Path: somewhat woolly. In particular it
does NOT say that the external class path is ignored!
Use the manifest. Distribute the JARs with the app.
I thought it might come to that. OK, next reality check:

All the relevant jar files came in RPMs or zip files. I unpacked them in
the same directory (/home/java symlinked as /usr/java) so they are
grouped with their documentation, etc. as separate trees. I'd like to
leave them that way for ease of maintenance, but when it comes to
distributing my jar file and simplifying its manifest it would be better
to have them all in the same directory. What about the following:

- make a directory to receive the jar file collection
- build the application jar file with a manifest saying that the
support jar files are in the same directory
- putting the application jar file in directory
- populate the directory with symlinks to the supporting jar files

I think that should work. Is there any obvious flaw? This way the
manifest file is installation-independent and distribution is easy: just
distribute a zip archive of that directory.
 
L

Lew

Martin said:
I was reading the "jar' manual in the SDK Documentation tree and
found its description of Class-Path: somewhat woolly. In particular it
does NOT say that the external class path is ignored!

That's because it's not a feature of the "jar" command, it's a feature of the
"java" command.

You will note that the link I provided is for the "java" command.
 
M

Martin Gregorie

Lew said:
That's because it's not a feature of the "jar" command, it's a feature
of the "java" command.

You will note that the link I provided is for the "java" command.
I hadn't - but have now found it. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top