Link to home
Start Free TrialLog in
Avatar of htam2000
htam2000

asked on

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 :(

Thanks
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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


SOLUTION
Avatar of kiranhk
kiranhk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Specify the full path to java.exe as petmagdy suggests.
Avatar of htam2000
htam2000

ASKER

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.

Would you give me an example of properties file?
I have no idea how to make this file :(
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start 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.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much!
Thank you too :).