0

So I've been trying to figure out how to run .java files because I was trying to run someone's program and I've been researching solutions for sooo long

cd "directory with file trying to run"
set path=C:\Program Files\Java\my-java-version-or-whatever\bin
javac Test.java (<-- name of file)

also tried

SET JAVA_HOME

and that worked and showed a path but when I did javac again it still didn't work. All help is much appreciated!!

And for some reason it just keeps saying that javac is not recognized.

Chai T. Rex
  • 2,972
  • 1
  • 15
  • 33
GeorgeDouj88
  • 49
  • 3
  • 11

2 Answers2

1

Please install JDK on your machine and point the JAVA_HOME to the same.

Find JDK Installation Directory

Open the default installation path for the JDK:

There should be a subdirectory like:

C:\Program Files\Java\jdk1.8.0_191

Set the JAVA_HOME Variable

Once you have the JDK installation path:

Right-click the My Computer icon on your desktop and select Properties.

Click the Advanced tab, then click the Environment Variables button.

Under System Variables, click New.

Enter the variable name as JAVA_HOME.

Enter the variable value as the installation path for the Java Development Kit.

Click OK.

Click Apply Changes.

Shiva
  • 1,962
  • 2
  • 13
  • 31
  • how do you do that? I went to the link that spandey15 provided and did everything except for the last one because I didn't know what to do and I tried everything, even ran CMD as admin and it still didn't work – GeorgeDouj88 Nov 16 '18 at 05:48
  • You cab download jdk 8 from here https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and you are free choose any version you would like to. – Shiva Nov 16 '18 at 05:51
  • What is the JAVA_HOME set? – Shiva Nov 16 '18 at 06:04
  • C:\Program Files\Java\jdk1.8.0_191 – GeorgeDouj88 Nov 16 '18 at 06:07
  • what is the result for `echo %JAVA_HOME%` – Shiva Nov 16 '18 at 06:12
  • C:\Program Files\Java\jdk1.8.0_191 – GeorgeDouj88 Nov 16 '18 at 06:13
  • This looks good enough. Hope you are not using multiple command prompts. one for setting `JAVA_HOME` and another for `javac`. The better can be done by updating environment variables. updating the answer with steps. – Shiva Nov 16 '18 at 06:17
  • You need to restart the command line if you updated using steps given in answer. – Shiva Nov 16 '18 at 06:24
1

If you have just set your JAVA_HOME make sure you restart your command console.

John Kim
  • 1,081
  • 10
  • 26