wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Executable Jar using the System Classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executable Jar using the System Classpath" Watch "Executable Jar using the System Classpath" New topic
Author

Executable Jar using the System Classpath

Steve Gibson
Ranch Hand

Joined: Jan 17, 2006
Posts: 37
Is there a way to get a Executable Jar to use the system classpath.

I have an app the uses the SqlServer jdbc driver, and if I specify the classpath in the manifest it works, but if I leave the classpath out of the manifest it can;t find the jdbc driver and the classpath for the jdbc driver is in the system classpath.

I really don't want to specify the classpath because it is very likely that the JDBC driver is already installed on the clients workstations.

All the workstations are XP sp2

Again, I have search the internet but have not turned anything up on this.
[ March 20, 2006: Message edited by: Steve Gibson ]

An insane man is perfectly sane in his own mind - cira 1984 a very young chemically altered S.Gibson<br /> <br />Yes we do build our software idiot proof, problem is they keep building better idiots. - (used by S.Gibson to break the tension during a confernece call with the CIO)
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Have you tried somethng along the lines of:

java -cp "%CLASSPATH%" -jar myjarfile.jar

I think that should probably work.


Fun programming etcetera!
Steve Gibson
Ranch Hand

Joined: Jan 17, 2006
Posts: 37
Originally posted by Dave Wingate:
Have you tried somethng along the lines of:

java -cp "%CLASSPATH%" -jar myjarfile.jar

I think that should probably work.


Nope.... does not work. Matter of fact specifing the complete classpath does not work either. I believe that I read on the web somewhere that a jar file ignores externally specified classpaths... but I have a hard time believing that (but it could be true).
[ March 20, 2006: Message edited by: Steve Gibson ]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Using the -jar switch will ignore the -classpath switch (and CLASSPATH environment variable). There are various available options - off the top of my head, and probably incomplete:
1. Use the Class-Path manifest entry
2. Repackage all your jars into one single jar
3. Don't use the -jar switch (instead specify a main class)
4. Write your own class loader to load from the various jars that would otherwise be in the classpath.

I generally prefer option 4.


Tony Morris
Java Q&A (FAQ, Trivia)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Steve]: I believe that I read on the web somewhere that a jar file ignores externally specified classpaths... but I have a hard time believing that (but it could be true).

Well the place to look for such info would be in the documentation, specifically under JDK Development Tools, the java program specifically, under standard options. Under the -jar option it says: "When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored." The oroginal idea of JAR files seems to have been that they'd be completely self-contained. That's not always practical, however, in which case use one of the alternatives Tony listed.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executable Jar using the System Classpath
 
Similar Threads
Program will not run on another machine.
Executable jar and the classpath
How classpath works for executable Jars
Jar file exception due to not finding Oracle driver but other standalone programs can use it
jar file prob