-3

As I tried compiling the java program it shows as,

'javac' is not recognized as an internal or external command, operable program or batch file.

As all know that this is because of the not setting the environment variable. But the thing I don't have access to add/modify the system variables.

Is there any way to by-pass this to make it run. Please advise.

Screenshot1:- enter image description here

enter image description here

DAIRAV
  • 723
  • 1
  • 9
  • 31

3 Answers3

1
  • Option 1: Set %PATH% in user environment variable instead of system.
  • Option 2: Use set path command on every new cmd which you launch to run/compile java
  • Option 3: Make .bat batch files having set path command to run/compile java [recommended for you]

How to make batch files(windows only) to run/compile simple java code?

  1. Create new text file
  2. Edit above file and add below contents to it: echo off cls set path=%path%;C:\Program Files\Java\jdk1.8.0_131\bin javac SourceFileName.java java MainClassName pause

  3. Save file and rename it as launch.bat

  • Thanks .. As im new to java , It could be much helpful if u could post the sample code to do so.. – Lazar Thomas Apr 25 '18 at 05:57
  • This is not a Java specific problem. It is a basic "how do I use the Windows command prompt" problem. You probably need to read a tutorial on how environment variables work. – Stephen C Apr 25 '18 at 06:20
  • Arvind - sorry ... my comment was really addressed to the OP ... in response to his "show me how to do it because I am new to Java" ... – Stephen C Apr 25 '18 at 06:24
0

Find out the path to javac on Windows using Windows Explorer C:\Program Files\Java\jdk1.8.0_161\bin and copy the path.

Add the path to environment variables like so:

Go to Control Panel, Environment Variables and Insert the address at the beginning of Path variable followed by a semicolon. i.e C:\Program Files\Java\jdk1.8.0_161\bin; . Do not overwrite the existing path, just append the javac path to what you find there. Apply/save these changes and exit control panel.

Close and reopen your command prompt. Try to compile again.

egimaben
  • 653
  • 7
  • 22
  • You might have overlooked my question. Please note i dont have access to set the environmental variables. SUggest a way to bye pass using cmd prompt .. – Lazar Thomas Apr 25 '18 at 06:57
  • @LazarThomas my bad, in that case, Arvind's solution above works :) – egimaben Apr 26 '18 at 04:54
0

THanks guys!!! Its worked..

set path=%path%;C:\Program Files\Java\jdk1.8.0_31\bin