Having trouble running javac from command line - java

I am trying to compile java files using either the command prompt or Git-Bash (running Windows 7) but I am having no luck. I've researched this and followed the simple steps of checking the version of Java I have by running:
java -version
from the command line and I get "1.8.0_102".
So I went to my PATH variable and appended:
;C:\Program Files\Java\jdk1.8.0_102\bin
I have checked what seems like a thousand times and this is the proper directory, but when I run
javac
from the command line, I still get the error
'javac' is not recognized as an internal or external command, operable program or batch file.
Can anyone huide me in the right direction?

Try to set
JAVA_HOME system variable to C:\Progam Files\Java\jdk1.8.0_102;
and add %JAVA_HOME%\bin; to your CLASSPATH variable
Then restart the command line and try

It's official, dumbest mistake I've made yet. I wrote
Progam Files
not
Program Files

Related

Java and javac not working in cmd. Both java and javac "is not recognized as an internal.."

I am having som trouble with java, i have tried to fix my Path, but i am new to programming and don`t know what to do.
I have java installed at : C:\Program Files\Java\jdk1.8.0_92\bin
and at : C:\Program Files (x86)\Java\jdk1.8.0_91\bin
Here are some screenshots from my system variables: This pops up when i click on the system variable "Path", see the other picture.
System variables
When I am in cmd, and writing java -version or javac -version, I get this message:
"java/javac is not recognized as an internal or external command, operable program or batch file".
Have tried to restart cmd every time i have changed the path.
Try Setting separate variables for JDK & JRE
Also give a backslash "\" after bin in the case of both JDK & JRE
Hope this works
First go to this path to make sure that it is right.
second try to restart your cmd and try again.

I was able to compile my java code from PowerShell, but cannot run it

I was able to compile and run my java code from CMD, however when I try to run the same commands in PS, I am getting error messages. I have read and been told that CMD commands will work in PS, but the CMD commands are not working in PS
Here is the line that I am using to execute my program:
java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
I am running the command from the directory where my needed JAR files are located. The error message says...
The command stanford-corenlp-3.8.0-models.jar was not found, but does exist
in the current location. Windows PowerShell does not load commands from the
current If you trust this command, instead type: ".\stanford-corenlp-3.8.0-
models.jar".
Made the change and the code looks like this now.
java -classpath .\;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
Still getting the exact same error message. I have also tried going up a directory and no luck. I have looked all over StackOverflow and I have done my research.
Any help would be much appreciated.
Thanks.
Using .\ would work for one file, but since you have a number of files, you should reference the current directory in each one of those files.
java -classpath .\stanford-corenlp-3.8.0.jar;.\stanford-corenlp-3.8.0-javadoc.jar;.\stanford-corenlp-3.8.0-models.jar;.\stanford-corenlp-3.8.0-models.jar .\Test.TestCoreNLP
Java 6 also supports wildcards, as this answer indicates, so you might try simply this.
java -cp ".\*" .\Test.TestCoreNLP
I came here with similar trouble, and what I found is that when running like this:
java -cp .\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar com.ethoca.app.myapp
I would get help info. My discovery is that I need to double-quote my list of classpath, like:
java -cp ".\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar" com.ethoca.app.myapp

Unable to set Java Path in system variables (Windows 10)

I've tried adding JAVA_HOME with the directory - C:\Program Files\Java\jdk1.8.0_121 to my system variables, and then adding %JAVA_HOME%/bin to Path variable and this didn't work and I receive
'java' is not recognized as an internal or external command, operable
program or batch file.
So I've tried adding C:\Program Files\Java\jdk1.8.0_121; directly to the path variable but I still get the above error. Does anyone have any suggestions please?
Thanks
PS - The image shows me in the command prompt at C:\Program Files\Java\jdk1.8.0_121 trying 'java -version' - I just moved up one dir to test the variable, entering 'java -version' in the bin directory returns the correct info, as you would expect.
Did you try closing that command prompt and reopening it?
In the command line, run the following:
set PATH=%PATH%:C:\Program Files\Java\jdk1.8.0_121\bin
Without exiting the shell, run your java commands
E.g.
java -version
This will surely work.

javac and java commands through Windows batch files

I normally compile things through the command line using:
javac -classpath . Test.java
Similarly, I run them through:
java -classpath . Test
I'm now attempting to save myself the trouble of typing these out every time through batch files. I have attempted to do so through another question from here:
Creating a batch file, for simple javac and java command execution
I've also tried my own way:
cmd.exe
#echo off
javac -classpath . Test.java
Still no luck, however. I have checked that my PATH environment variable is correctly pointing to the latest version of jdk and as I've said, I can compile just fine directly through command line. Upon running the batch file, I just get the command prompt with no error; as if there was nothing under cmd.exe. Could anyone lend a helping hand and slap some sense into me?
When you write cmd.exe, that will start a new command prompt. You don't want that.
When you write #echo off, that means nothing will be printed on the screen after that point. That's what it means. That's what it does. That is why it looks like nothing is happening.
Something would be printed to the screen if you had a compilation error, but probably you don't.
If you want the command prompt window to stay around instead of disappearing, I believe there is an option in Windows to configure that, at least there was when I last used Windows, back in the mists of time.
this worked for me. I think it does what you were looking to do.
This is the code I suggest for the .bat file:
cd C:\Users\John\JavaApps\folderThatContains.java //points terminal to folder
javac Main.java //This compiles .java in said folder
cmd /K "java Main" //cmd /K prevents terminal from quitting after "java Main"

javac not working in CMD

I'm having a issue with compiling java from my Command Prompt. At first it was saying javac isn't a recognised internal or external command and by reading up I see you need to change the path and thats what I did exactly to...
variable name: path
variable value:%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%path%;C:\Program Files\Java\jre7\bin;
I closed commpand prompt and attempted it again however the same issue came up.
I then tried echo %path% and the entire path line was echoed(entire line in terms of that variable value)
I also have tried "for %i in (javac.exe) do #echo %~$PATH:i" and that returns ECHO ON.
I'm quite stumped and confused now. My javafile is in and named main.java however I am trying to compile it whilst in the javawork folder in CMD
C:\Users\MYNAME\Documents\Javawork
Thanks,
You want the path to the JDK, not the JRE, in your system path. The JRE doesn't come with a compiler (javac).
To compile Java code you need to install the Java Development Kit (JDK) as javac.exe isn't included in the Java Runtime Environment (JRE).
The path should point to the bindirectory of the JDK.

Categories

Resources