Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

classpath and jarfile question

Thread view: 
Martin Gregorie - 01 Nov 2007 14:09 GMT
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

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Lew - 01 Nov 2007 15:04 GMT
>   "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.

Signature

Lew

Martin Gregorie - 01 Nov 2007 19:24 GMT
> 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.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Lew - 01 Nov 2007 20:30 GMT
> 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.

Signature

Lew

Martin Gregorie - 02 Nov 2007 00:19 GMT
>> I was reading the "jar' manual in the SDK Documentation tree and found
>> its description of Class-Path: somewhat woolly. In particular it does
[quoted text clipped - 4 lines]
>
> You will note that the link I provided is for the "java" command.

I hadn't - but have now found it. Thanks.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Andrew Thompson - 02 Nov 2007 05:05 GMT
...
>   "java -jar jarfile.jar arguments...."

java -cp jarfile.jar com.the.MainClass arguments....

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.