• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

running java

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running java from the command prompt. If I am in the same directory as the package where my classes are located, I just type java <package>/class and my program works. If I am not in the directory where the package is located then I get an error. eg java /home/test/<package>/class generates an error.
Does anyone know how do I run from the prompt if I am not in current directory of the package.


Thanks
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm actually surprised that java <package>/class works for you because it shoudl be java <package>.class, afaik. In order to get this to work from any directory, you need to set your system's CLASSPATH variable. Look at this page for instructions on how to set this system variable. You just have to set the value to the directory that contains your package. You may also want to add the current working directory (.) to your classpath. The link above should explain what I mean by this. Of course, if you still have questions, let us know.

Keep Coding!

Layne
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gamb,

It's one of the most annoying things about Java when you're first learning the language, but after you've gotten package stuctures and classpath understanding under your belt, it's a lot easier.

Just as a side to this question, I'd mention about having .jars in your classpath as well. You should know that they must be declared individually in your path. I mean that you cannot have a pile of jars in some directory and then declare that directory as your classpath. This confuses a lot of people in the early going.

David
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic