Sunday, August 2, 2009

How can i set the path in java program?

I installed jdk1.5.0 update 2 and wanted to set permanent path so that i can write programs in java but when i wrote javac in command prompt answer was ' javac is not recognized as internal or external program.

How can i set the path in java program?
i'm assuming you're on windows. If you are you can include the path to this .exe in the path parameters.





From the command prompt:


set path = %path%;[path to folder containing .exe]





i'm not sure how to do it on other platforms, but it should be something similar regarding setting environment variables
Reply:I think it is good to make sure you type in the path correctly. It want to tell you about .bat file. I will automate your coding.





Open Notepad, type in:


javac C:\Program Files\Java\jdk1.6.0\bin\javac MyClass.java





save that file as "compile.bat" into your folder with your current work project.





Start another file in Notepad, type in:


java .\;C:\ProgramFiles\Java\jdk1.6.0\bin\jav... MyClass





Note, just after java the .\; that is look here first, java, this folder. The semicolon is the DOS end-of-line. The rest is the path to the java engine, a space the Java program you compiled.





Save that as "run.bat" in the same folder.





Now, you can double-click the .bat file. If it fails, make sure the path points to the bin folder inside JDK folder. It can be tricky. You see, in DOS the folders are \ (backslash). In java, in the internet, everywhere else, the path folders are "/".





If you .bat files work, great. Change your environment variable. You can then make your next bat files without the path.


javac MyJava.java





java MyJava





And finally, the NetBeans IDE does this bat file automatically for you every time you run code. NetBeans is a great editor, colors the keywords and helps you code.


No comments:

Post a Comment