Javac not working on windows command line

javac not working on windows command line

^ I tried the suggestions on this post, and it was WRONGLY useful, but not completely.

I opened my command line and I entered "javac" after entering the path into my environment variables, and this did not work, after which I looked through it and found this stream.

I knew that I had already closed and reopened my cmd and it didn’t work, so I skipped this bit and I saw the part telling me to make sure javac.exe exists and I checked it with the command " dir "in cmd. Afterwords, while in the folder β€œC: \ Program Files \ Java \ jdk1.7.0_25 \ bin" on the command line, I entered the following tip, which was

for %i in (javac.exe) do @echo %~$PATH:i 

After entering this in my command prompt, I received the message "ECHO is enabled." Seeing this, I again typed "javac", and this time it worked. So I decided to check this by backing up from the directory and going to the folder in which the .java file was saved and run, but he again told me that

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

It was disappointing. I think this will only work if I INSIDE the bin file on the command line, which is annoying because I am not the administrator of this computer, and it will be very unpleasant to always get administrator permission (from my parents) for encoding. They will also never give me a password. Can someone help me? Thank you in advance! And sorry for the huge wall of text ...

EDIT: Someone asked what the output would be "echo% path%". It:

 C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\ 

^ Is this supposed to be said?

EDIT 2: @ brano88 ... I guess I did? I right-click on the computer, go to properties, go to advanced system settings, click environment variables and go to the top and click "Create ...". There I entered the variable name as the path and the variable value as the bin location. This is not true? In doing so, I followed the YouTube tutorial step by step.

This one: http://www.youtube.com/watch?v=Hl-zzrqQoSE

+4
source share
5 answers

How to run .java files from CMD

  • go to your computer β†’ C: β†’ Program Files β†’ Java β†’ jdk1.7.0_25-bin
  • copy the path (example: C:\Program Files (x86)\Java\jdk1.7.0_25\bin )
  • Go to Control Panel β†’ System and Security β†’ System Advance Settings β†’ Advanced β†’ Environment Variables
  • open the "Environment Variables" screen and go to "System Variables" and find "Path"
  • after finding the system variable Path, double-click on it or click the edit button, and in the Variable value, you paste the path from the java that you just copied after the last values ​​were added.
  • Note!
    • make sure that you DO NOT enter extra space in this field, as it will not work;
    • make sure you have one semicolon before inserting the path, for example: Path : ...%ANT_HOME%\bin;C:\Program Files (x86)\Java\jdk1.7.0_25\bin
  • Note! If you previously tried to compile a .java file in CMD, close CMD and open it again, since the changes will take effect only with the use of a new instance of CMD
  • Go to the file.java folder, for example: E: \ Projects, right-click while holding down the Shift button inside your folder and in the parameters from the window that just appeared: Open the command window here
  • Another solution is to open CMD normally and change the directory using: cd until you reach your folder
  • After opening the CMD window, enter: javac HelloWorld.java
  • Note! Make sure the class name written in file.java matches the file name. For example, your file name should be: HelloWorld.java , and your class inside this file should also be:

    class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } }

Otherwise, it will not compile! This is successful if an error message is not displayed, if the folder path appears again in the CMD, and, of course, if the HelloWorld.class file appears in the directory. To test this type, select the dir command, which will show what your currect directory contains.

  1. To finally run the file type in CMD: java HelloWorld
  2. Note that the file extension does not need to be run. The file you have already run has the extension .class .

Here's how it worked for me! If something is wrong, please let me know! Thanks!

+6
source

For a novice programmer who does not have administrator privileges on his computer, I would recommend the Eclipse IDE.

Since you already have a JDK, the only required installation step does not require administrator rights. From here you should download the "Eclipse Standard" option and you will get a very large zip archive. You can extract it to the desktop or my documents. Windows comes with a utility for this by dragging and dropping directly from Explorer, or another program, such as WinRAR, may be installed on your computer to do this.

Then you can run eclipse.exe from where you extracted it by viewing and double-clicking this file.

The IDE is very powerful and straightforward. You can create projects, run and debug code, and this is good for beginners. It really is worth the wait while loading.

+1
source

Firstly, yes, you added JDK to PATH. But you did not do it right. You have already added these variables to PATH: C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

To add the JDK, put a semicolon before adding it, because you have several paths assigned to the PATH variable. Therefore, it should be something like this:

C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_25\bin

+1
source

in my case, javac did not work just because when specifying the path to javac in the path variable, I gave a space after putting a semicolon at the end of the previous entry

+1
source

To use javac from the command line without typing the full location every time you need to add it to the path.

I am not sure that you can change it without administrator rights. But in Windows 7 with administrator you can start β†’ Right click My Computer β†’ Properties β†’ Advanced System Settings β†’ Advanced β†’ Enviromental Variables

Then you can find the path to the system variable and add the end to it, the javac location.

The exact location of javac will depend on the version of JDK you installed. During installation, you will be given the opportunity to choose where it was installed.

EDIT: Also make sure that you do not open cmd as an administrator. Or follow the steps of this video in the administrator account.

Adding variables to the top of the menu of environment variables means that they only affect the current user. You should be able to do this on a regular account if you have someone like an administrator password.

0
source

Source: https://habr.com/ru/post/1491535/


All Articles