• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't find jar file in CLASSPATH in Fedora 5  RSS feed

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I set my CLASSPATH to /home/yinglcs/lib/batik-1.6, but when I execute 'java -jar batik-rasterizer.jar', it said 'Unable to access jarfile batik-rasterizer.jar', can you please tell me what am I missing?


$ echo $CLASSPATH
/home/yinglcs/lib/batik-1.6
$ java -jar batik-rasterizer.jar
Unable to access jarfile batik-rasterizer.jar
$ cd /home/yinglcs/lib/batik-1.6
$ ls -la batik-rasterizer.jar
-rw-rw-r-- 1 yinglcs yinglcs 40062 Apr 10 2005 batik-rasterizer.jar
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

The classpath is not used to find JAR files. It is used to search for class files. So putting a directory that contains a JAR file in the classpath doesn't make Java look for the JAR file in that directory.

Also, when you are running an executable JAR file with "java -jar ..." then the CLASSPATH environment variable is not used at all. In that case the classpath that is specified in the manifest file of the JAR is used instead.

Try cd'ing to the directory that contains the JAR file and then type "java -jar ...".
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I am trying to write a shell script in linux which does this "java -jar myJar.jar"

But user can run this script anywhere he/she wants, how can I configure the script where it should look up myJar.jar?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ying lam:
Thanks.
I am trying to write a shell script in linux which does this "java -jar myJar.jar"

But user can run this script anywhere he/she wants, how can I configure the script where it should look up myJar.jar?


I think the easiest way would be to include the absolute path to myJar.jar in the script.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!