PDA

View Full Version : Java Running Classes



DBQ
October 9th, 2008, 05:02 PM
In java suppose I have a class c1 in a package p1. Hence this will be represented as file c1.class in director p1.

Is there any way to run this class from ANY path? ie. not just java p1/c1?

Suppose I want to run the class as follows java /home/me/dir1/dir2/p1/c1. The reason I want to do this is so that the process treat /home as its working directory. Is there any way to do this? Please forgive if this is a simple question.

Thank You

Zugzwang
October 9th, 2008, 05:36 PM
Sure. You can either package your Java program in a .jar file which you can execute from anywhere *or* tell the "java" command where to look for classes:


java -cp /home/me/dir1/dir2/ p1.c1

drubin
October 9th, 2008, 08:26 PM
http://en.wikipedia.org/wiki/JAR_(file_format)

http://java.sun.com/docs/books/tutorial/deployment/jar/