Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on setting CLASSPATH on linux

 
rick collette
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
rick collette
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
although you are exporting CLASSPATH but you are not setting it for java runtime.
Try this
java -jar -classpath $CLASSPATH application.jar
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic