wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes A question on setting CLASSPATH on linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "A question on setting CLASSPATH on linux" Watch "A question on setting CLASSPATH on linux" New topic
Author

A question on setting CLASSPATH on linux

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hi,
I have a jar file in the following subdirectory on my home directory:
app/application.jar
In order to run application jar in any directory,
I have to set classpath, right? How can I set
appropriate class on linux to all me to run
it directly, for example, from my home directory
like this?
[home]$ java -jar application.jar
I am not familiar with this on Linux, any help appreciated.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I don't think you need to set the classpath for this. Why not just use the full path to the jarfile?
java -jar /home/myname/app/application.jar


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Originally posted by Frank Carver:
I don't think you need to set the classpath for this. Why not just use the full path to the jarfile?
java -jar /home/myname/app/application.jar

Thanks. The trouble is the data file has to sit
on the same directory as application.jar, the access to it will be refused if I do not execute the application from subdirectory app. I try to
set classpath like this:
export CLASSPATH=/home/myname/app/application.jar
the I use the following command to execute it:
java -jar -classpath application.jar
It did not work, I ma not sure if I did not set
the right classpath, or my command was not right.
Any ideas?
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
although you are exporting CLASSPATH but you are not setting it for java runtime.
Try this
java -jar -classpath $CLASSPATH application.jar


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I still think the problem is not with the classpath. Try putting the following into a file "myapp", somewhere which is in the regular execution path:

then make it executable:

Now you should be able to run your application, data and all, by typing "myapp" from anywhere.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question on setting CLASSPATH on linux