How to hard code the absolute path in my java program?

To make question clear here -
Machine - windows platform (os - win2000)
I don't have administrator privilege. I can't install or alter anything else.

I run my java program by using third party java application tools (everything is ok!!!).
If I want to run a java program in a command line i.e. I intend not to use that third party java application tools to run my java program, then I got the message said "java runtime environment not found" and "no java" command something like that. Obviously, the environmental variable and the path linking are not configured properly.
I would wonder that is it possible to write an absolute path in my java program or any idea how to get around this? Then, my java program can run in a command line :(

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to set up the PATH variable for your account, adding the java bin directory
You can do that with the System 'applet' in Control Panel
or just instead of run:

java urapplication

c:\urjavapath\java urapplication

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

you can create a temp variable on the Environment variables in the Advanced tab of the System applet as told by CEHJ.
otherwise u create a batch file which will set the path and classpath specific to ur application and everytime u open a cmd prompt run the batch file and start executing ur java programs.
something like setEnv.bat
set path=%path%;c:\yourpathfor java
set classpath=%classpath%; c:\your classpath for ur application
Specify the full path to java.exe as petmagdy suggests.
htam2000Author Commented:
I am getting more confuse.....
What happens with javac?
typed in  ---  c:\>java -fullversion
output    ---  c:\>java full version "1.4.0_04-b04"

typed in  ---  c:\>javac -?
output    ---  'javac' is not recognized as an internal or external comand, operable program or batch file.

What is wrong with that?
I think the path is ok, since  c:\>java -fullversion works.....
How can I compile my java program?
you haven't added the bin directory of your jdk in your PATH, either add it or specify the full path to javac on the command line
> output    ---  'javac' is not recognized as an internal or external comand, operable program or batch file.
> What is wrong with that?
> I think the path is ok, since  c:\>java -fullversion works.....

You may have only a Java Runtime Environment installed.  
The JRE can execute java byte-code, but does not include java
development tools such as the compiler, javadoc, etc.
I suggest you to use a configuration file, in the same directory as your application (in the application working directory). That configuration file could be a properties file. This way is more flexible than hard-coding the path to the java executable in your code. That path could differ between computers, and you will need to specifically compile the code for each one of them.

Having a properties file is very simple, and can contain a predefined path to the java executable but you will need to instruct your users to set that variale correctly in case the application is not starting.

htam2000Author Commented:
Would you give me an example of properties file?
I have no idea how to make this file :(
A properties file is a file ended with extension .properties., like
This file contains pairs of key-values elements, like:


Supposing all the above are stored in a file, in the working directory of your application.
Insideyour code, you have to do something like:

    String configPath = System.getProperty("user.dir") + File.separator + "";
    Properties startupProperties = new Properties();

    try {
      startupProperties.load(new FileInputStream(configPath));
    } catch (IOException e) {

After you have loaded them in the 'startupProperties' object, you can use the object in the same manner you use an hashtable.


String javaHomePath = startupProperties.getProperty("java.home.path");


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Of course, this is not a solution for storing the path to the java executable. The program won't run in the first place, because is not aware of java. But this is a general way of loading some predefined settings in an application. For more informations on Properties class, please review the API docs for java.util.Properties.

This is just detail of what  CHEJ
Do a search for Javac.exe

If I do a search on MY COMPUTER I find this

so I could
a) type C:\jdk1.3.1_02\bin\javac.exe to run javac.exe
b)set path=%path%;C:\jdk1.3.1_02\bin
then I can type javac in any directory C:\mycomputer c:\winnt etc.

as far as
set classpath=%classpath%;
Do a search for *.jar, whatever dir comes up, add to this variable as well.

Then run javac in whichever dir you .java files reside.

This can be done also by clicking START>CONTROL PANEL>SYSTEM>ADVANCED>ENV VARIABLE. This only needs to be done once here.
htam2000Author Commented:
Thank you very much!
Thank you too :).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.