Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing java from another directory

 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to execute java class file resinding in another directory eg;-
if i am executing from c:\test and the class file is in c:\home\agent\test.class
how to give execution coomand for this
c:\test>java test
thanks in advance
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the CLASSPATH environment variable. See http://faq.javaranch.com/view?HowToSetTheClasspath.

[Fixed link - Jim]
[ August 09, 2005: Message edited by: Jim Yingst ]
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the responce
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting CLASSPATH is problematic if not evil and best avoided. Instead add the required jars for your program to your launch script: java -classpath ...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the classpath argument to the JVM or set the environment variable just for one run. Frinstance I have no classpath in my environment by default, and this is a typical batch file for me ...
 
Norm Radder
Ranch Hand
Posts: 887
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another consideration when setting the classpath is if the class is in a package. Then you need to adjust the path so that it plus the package gives the complete path to the file.
For example if the package is agent and the file is at C:\files\region1\agent\pgm.class
then the classpath should be:
C:\files\region1\
When you execute you need the package as part of the name:
java agent.pgm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic