• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executable Jar using the System Classpath

 
Steve Gibson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried somethng along the lines of:

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

I think that should probably work.
 
Steve Gibson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic