Home arrow static arrow Java Programming [Archive] - question about classpath and jar file
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - question about classpath and jar file
This topic has 12 replies on 1 page.

Posts:102
Registered: 10/2/03
question about classpath and jar file  
Aug 4, 2004 12:14 PM



 
I have a jar file (actually jhall.jar, the java help jar file). How do I uses its classes if I don't want to add it to the classpath. Currently, I have the jar file in the same directory as all my other classes.
 

Posts:2,206
Registered: 8/15/02
Re: question about classpath and jar file  
Aug 4, 2004 12:16 PM (reply 1 of 12)



 
You could put it in $JAVAHOME/jre/lib/ext, otherwise you will need to add . to your classpath
 

Posts:102
Registered: 10/2/03
Re: question about classpath and jar file  
Aug 4, 2004 12:24 PM (reply 2 of 12)



 
hmm, what if I need to install this on somebody else's computer and they only have j2se libraries installed. How would I add classpath in that case? Sorry, for some reason I have trouble adding classpath (probably because I'm stupid)
 

Posts:31,095
Registered: 4/30/99
Re: question about classpath and jar file  
Aug 4, 2004 12:26 PM (reply 3 of 12)



 
What EvilEdna said.
 

Posts:2,206
Registered: 8/15/02
Re: question about classpath and jar file  
Aug 4, 2004 12:28 PM (reply 4 of 12)



 
In that case you have two options - in you installation guide get the users to install it (bad solution, naughty Edna for even thinking it, now I must be spanked)

Or....

Bit the bullet and learn about classpaths. If you are just running you app from the command line and you are in the directory where your class files are you can just use
java -cp . myJavaApp
 

Posts:21,718
Registered: 98-02-20
Re: question about classpath and jar file  
Aug 4, 2004 12:32 PM (reply 5 of 12)



 
Bit the bullet and learn about classpaths. If you are
just running you app from the command line and you are
in the directory where your class files are you can
just use
java -cp . myJavaApp

Don't you still have to add individual JAR files to the CLASSPATH?

Learn about CLASSPATH no matter what you do. Every Java programmer must have a good understanding of it.

Better yet, learn about executable JARs, manifest files, and the Class-Path entry.

%
 

Posts:2,206
Registered: 8/15/02
Re: question about classpath and jar file  
Aug 4, 2004 12:35 PM (reply 6 of 12)



 
Oh yeah. Heres a (cut down) example from a script I use...
set CLASSPATH = ../lib/gemini.jar:../lib/orac.jar:../lib/odb.jar

${JAVA} -classpath ${CLASSPATH} myPackage.myAppPackage.myApp
 

Posts:89
Registered: 3/4/02
Re: question about classpath and jar file  
Aug 4, 2004 1:15 PM (reply 7 of 12)



 
if its kinda application better to have it in some script (shell or batch), set the classpath at the start and then call the actual program. Or if you really just DONT want to use classpath then put your jar file with other j2ee jar files.
 

Posts:102
Registered: 10/2/03
Re: question about classpath and jar file  
Aug 5, 2004 6:57 AM (reply 8 of 12)



 
thanks, everyone. I think I will see if I can get the installer to copy the file into the java home directory's external library folder, if not, I will do the classpath.
 

Posts:102
Registered: 10/2/03
Re: question about classpath and jar file  
Aug 5, 2004 11:12 AM (reply 9 of 12)



 
I noticed when I go
jar -uvmf manifest.txt firstjar.jar secondjar.jar

it simply adds secondjar.jar into firstjar.jar, rather than extracting secondjar.jar's files and put it into firstjar.jar. How would I be able to do that?

Thank you.
 

Posts:31,095
Registered: 4/30/99
Re: question about classpath and jar file  
Aug 5, 2004 11:26 AM (reply 10 of 12)



 
it simply adds secondjar.jar into firstjar.jar, rather
than extracting secondjar.jar's files and put it into
firstjar.jar. How would I be able to do that?

Don't do either of them. Distribute the two jar files separately, and in the manifest of the one which is meant to be your executable jar file, put a Class-Path: entry that refers to the other one. Look at the latter parts of the tutorial about jar files:

http://java.sun.com/docs/books/tutorial/jar/basics/

PC²
 

Posts:102
Registered: 10/2/03
Re: question about classpath and jar file  
Aug 5, 2004 12:17 PM (reply 11 of 12)



 
okay, just wondering: what is wrong with having this in a manifest file (called manifest.txt):

Main-Class: Main

Class-Path: jhall.jar

so, I already have a jar called PerkSort.jar and I want to be able to use the classes in jhall.jar. I tried to update using

jar -umf manifest.txt PerkSort.jar

it gave the error of invalid manifest format.

 

Posts:31,095
Registered: 4/30/99
Re: question about classpath and jar file  
Aug 5, 2004 1:36 PM (reply 12 of 12)



 
I dunno, from my reading of the manifest specification it looks like the Class-Path entry has to be first. And it doesn't say you can leave blank lines between the entries. But the specification looks like it was written by somebody who thought having a grammar describing the format of a manifest was way cool but didn't get it to be either precise or understandable. On my computer the manifest spec is at

file:///C:/j2sdk1.4.2_04/docs/guide/jar/jar.html#Manifest%20Specification

I expect it's at a similar place on yours.
 
This topic has 12 replies on 1 page.