This question already has answers here:
javac is not recognized as an internal or external command in windows 7
(3 answers)
Closed 2 years ago.
My current system config is -
Netbeans 12.0
JDK 14.0.2
Windows 10 (64bit)
I have added the environmental variable in PATH manually i.e. C:\Program Files\Java\jdk-14.0.2\bin.
I tried adding using cmd as well. As well as adding the JAVA_HOME as a new variable with value as C:\Program Files\Java\jdk-14.0.2 .
I have used the set command to do this process i.e. set path = "%path%;"C:\Program Files\Java\jdk-14.0.2\bin". Also, I have used the same command without the set keyword.
Since javah command was deprecated for versions of jdk>8, I have tried to use javac -h command as well.
I have also tried to install JDK v. 8.0.2 instead of the current one.
Although there's no javah.exe file in the bin folder, there is however javac.exe file.
I have uninstalled and reinstalled JDK and Netbeans quite a few times.
I am currently working on JNI with Netbeans IDE and C/C++ plugin. (I have successfully installed Cygwin and necessary extension for the file to build. Although I don't know how they affect this problem, still I thought I should add this).
The command I wish to use with 'javah' is the one used for creating a C header from a Java class i.e. 'javah -o JNIDemoJava.h -classpath JNIDemoJava/build/classes jnidemojava.Main'.
But due to this error, I have been stuck for a few days. Please do assist.
Following way you can set Path variable temporary(it can only be used in the same command line):
You should do it this way:(notice =)
set PATH=C:\Program Files\Java\jdk-14.0.2\bin
And if you set JAVA_HOME variable correctly you can do it this way:
set PATH="%JAVA_HOME%\bin"
For setting this permanently read this post :
https://javatutorial.net/set-java-home-windows-10
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
In this case use
set path=C:\Program Files\Java\jdk-14.0.2\bin to set JAVA_PATH
Related
I have Oracle JDK 17 installed on my system at the default location in my Windows 10 OS.
I can use the javac compiler from the command line.
I am going to install GraalVM JDK [java17] in my system (zip file) at a different location.
Online docs have instructed me to add the path to GraalVM bin directory (Eg C:\path\graalvm\bin) to the PATH variable on Windows .
Now when i type C:\javac mySourceFile.java and press enter
How will the OS decide which java compiler(oracle javac /GraalVM javac) will it use to compile the source code as both of them are named javac ?
Here i am not explicitly passing the location of the javac to be used.
is there any way to specify which jdk to use at command line?
Please note that compiling is done using command line tools only and no IDE is used.
(I am aware that IDE's allow you to select the JDK based on the location using preferences/settings)
When you type "javac MyClass.java", the path list defined in the PATH variable will be searched from left to right. When it finds a match, it will use that command. So, it's possible you may have include multiple java\bin folders in the path. It will execute the first one it finds. If you want a particular version of Java to execute, add it as the first path to the path variable.
I have installed Java 8 and set my JAVA_HOME and JRE_HOME paths and added %JAVA_HOME% to the start of the path variable.
I created a helloworld.java application and am able to compile it using:
javac helloworld.java
However, when I try to run:
java helloworld
I get the error:
The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
How can I solve this?
1.Just go to C:\ProgramData\Oracle\Java\javapath\
2.You will find there shortcuts for java.exe,javaw.exe,javaws.exe which are pointing to a location where they actually are not existing now
3.Go to the jre location where you have installed java like C:\Program Files\Java\jre6\bin
You will find java.exe,javaw.exe,javaws.exe
Create shortcuts for these files and replace with the ones which are present in C:\ProgramData\Oracle\Java\javapath.
It works
Just set %JAVA_HOME%/bin to your path variable.
If you are blocked from modifying system variables from command line, but are able to open up an elevated command prompt, then run a command like this:
setx \M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_25"
But of course, change the directory to point to your installed version of java. Note that the JAVA_HOME path does not point into the bin directory, it stops one level above bin.
I was able to solve this issue. To do so I used the advice from this answer:
Java SE Development Kit 8u25 on a 64-bit Windows 8
Set the following user environment variables (== environment variables of type user variables)
•JAVA_HOME : C:\Program Files\Java\jdk1.8.0_25
•JDK_HOME : %JAVA_HOME%
•JRE_HOME : %JAVA_HOME%\jre
•CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
•PATH : your-unique-entries;%JAVA_HOME%\bin
(make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.)
I am trying to extract a jar file from Matlab code using javac from Library Compiler (java package).
I have set JAVA_HOME to:
C:\Program Files\Java\jdk1.7.0_71
and added to PATH:
C:\Program Files\Java\jdk1.7.0_71\bin.
When I enter java -version in my console, I get java version jdk1.7.0_71 and running javac -version shows jdk1.7.0_71.
However, it seems that matlab could not find javac, thus, I am not able to compile my .m code into a .jar file. When I tried to compile .m code I got the following:
Error: An error occurred while shelling out to javac (error code = -1).
Unable to build executable.
Executing command: ""C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac" -verbose - classpath "...\MATLAB\R2014a\toolbox\javabuilder\jar\javabuilder.jar" -d "...\features_extraction\for_testing\classes" "...\features_extraction\for_testing\features_extraction\Class1.java" "...\features_extraction\for_testing\features_extraction\Features_extractionMCRFactory.java" "...\for_testing\features_extraction\Class1Remote.java" "...\for_testing\features_extraction\package-info.java""
This is the directory of my java bin folder and javac.exe exists : ...\Java\jdk1.7.0_71\bin\bin\javac? I found this link for compatibility between Java and Matlab2014a(which is my version) here. What should I check in order to correctly link Matlab to Java? A few days ago Matlab was working correctly with Java.
In my PATH I noticed the existence of the following path: C:\ProgramData\Oracle\Java\javapath in which there are three wrong shortcuts to java.exe, javac.exe, and javax.exe. When I type in matlab console getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode. When I write javac in matlab console I am getting: Undefined function or variable 'javac'.
When I try to built C++ library I got a similar issue: Error: An error occurred while shelling out to mbuild (error code = -1).
Unable to build executable.
EDIT: Does the absence of the proper MCR counts in my case?
You said
getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21
try to use setenv in MATLAB, doc here http://www.mathworks.com/help/matlab/ref/setenv.html
setenv('JAVA_HOME','C:\Program Files\Java\jdk1.7.0_71');
setenv('PATH','C:\Program Files\Java\jdk1.7.0_71\bin');
Following from the answers in this link
http://www.mathworks.com/matlabcentral/answers/131639-matlab-deploytool-not-working-fails-while-building
seems like you have to install JDK 1.7.0_11-b21, which is the one your MATLAB version is compatible with for compiling into jar. Also, after installing that specific version, you should modify the JAVA_HOME and PATH environment variables. Try that to see if it helps.
I was having a very similar problem with my installation.
I set the environment variable (press > type env > Enter) JAVA_HOME (under "User variables") to my JDK home directory (not the bin folder) without any trailing \ or ;.
The problem occurs because MATLAB cannot execute javac properly, however, in order to work out exactly what MATLAB is trying to execute (which is not working) we need to use the command window and not the Library Compiler.
It appears you have already done this but for completeness I will add the process here for others.
To find what MATLAB executes, click "Open log file" and copy the entire first line.
Paste the first line in the MATLAB command window and add -v to the end.
Press enter to run the command and note the "Executing command:" that is printed to the screen.
Once you have the "executing command" that MATLAB returns for you, check the first path in that command and make sure it matches your javac file.
In your original post you have done this and posted
C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac
a path which contains \Java\Java, if this isn't a typo then it may be a problem as it is not the default Java installation path. You also say after that your installation is at
...\Java\jdk1.7.0_71\bin\bin\javac
which contains \bin\bin and is also not the default java bin install directory, perhaps another typo?
If the path to javac matches exactly you could try copying and pasting the "executing command" into your OS's command window (+R > cmd > Enter) and looking for errors. By doing this we can remove ourselves from the MATLAB installation and if errors still exist it likely has nothing to do with MATLAB.
To see if the same problem could be caused by other environment variables I removed every other path to a java installation (keeping JAVA_HOME) in my environment variables. MATLAB uses the absolute path to the java installation and so it was still able to compile with javac using only the JAVA_HOME environment variable.
I have recently installed sqldeveloper but i'm getting the below warning window when I try to launch it. This is causing the sqldeveloper to run very very slow and it hangs frequently
I have tried editing the file sqldeveloper.cong as suggested in the window above but does not work
Original
SetJavaHome ../../jdk
Update 1
SetJavaHome C:\Program Files\Java\jdk1.7.0_60\bin\ and all other variations but still getting the above warning window
Update 2
SetJavaHome C:\Program Files (x86)\Java\jre7\bin and all other variations
Please suggest the correct way
The message seems to be out of date. In version 4 that setting exists in two files, and you need to change it in the other one, which is:
%APPDATA%\sqldeveloper\1.0.0.0.0\product.conf
Which you might need to expand to your actual APPDATA, which will be something like C:\Users\cprasad\AppData\Roaming. In that file you will see the SetJavaHome is currently going to be set to the path to your Java 1.8 location, so change that as you did in the sqldeveloper.conf:
SetJavaHome C:\Program Files\Java\jdk1.7.0_60\bin\
If the settig is blank (in both files, I think) then it should prompt you to pick the JDK location when you launch it, if you prefer.
another thing you could try is to rename your old jdk folder, lets say its:
C:\Program Files\Java\jdk1.7.0_04
change it to saomething like:
C:\Program Files\Java\xxxjdk1.7.0_04
Now, you should once again asked to set your jdk folder location on Oracle SqlDeveloper launch, and you can chose the right path.
Not the most elegant solution, but it worked for me.
Milos
In your SQL Developer Bin Folder find
\sqldeveloper\bin\sqldeveloper.conf
It should be
SetJavaHome \path\to\jdk
You said it was ../../jdk originally so you could ultimatey do 1 of two things:
SetJavaHome C:\Program Files\Java\jdk1.7.0_60
This is assuming that you have JDK 1.7.60 installed in that directory; you don't want to point it to the bin folder you want the whole JDK folder.
OR
The second thing you can do is find the jdk folder in the sqldeveloper folder for me its sqldeveloper\jdk and copy and paste the contents from C:\Program Files\Java\jdk1.7.0_60. You then have to revert your change to read
SetJavaHome ../../jdk
in your sqldeveloper.conf
If all else fails you can always redownload the sqldeveloper that already contains the jdk7 all zipped up and ready for you to run at will: Download SQL Developer The file I talk about is called Windows 64-bit - zip file includes the JDK 7
I cannot believe Oracle's documentation is SO LAME! In some documents it is misleading people to point to the JDK by specifying the path to the JDK root, e.g. on a Mac:
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/
Reviewing /Applications/SQLDeveloper.app/Contents/MacOS/sqldeveloper.sh
revealed the method they use to set up the path:
TMP_PATH=/usr/libexec/java_home -F -v 9
if [ -z "$TMP_PATH" ] ; then
TMP_PATH=/usr/libexec/java_home -F -v 1.8
if [ -z "$TMP_PATH" ] ; then
osascript -e 'tell app "System Events" to display dialog "SQL Developer requires a minimum of Java 8. \nJava 8 can be downloaded from:\n http://www.oracle.com/technetwork/java/javase/downloads/"'
exit 1
fi
fi
Executing this manually from Terminal:
/usr/libexec/java_home -F -v 1.8
Lists the path as:
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
And this is what you need to specify as the value for
SetJavaHome /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
Thank you Oracle for wasting half a day on your "product" that does NOT even support your latest Java version, also released by you.
On Windows,Close all the SQL Developer windows. Then You need to completely delete the SQL Developer and sqldeveloper folders located in user/AppData/Roaming. Finally, run the program, you will be prompted for new JDK.
Note that AppData is a hidden folder.
For those who use Mac, edit this file:
/Applications/SQLDeveloper.app/Contents/MacOS/sqldeveloper.sh
Mine had:
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
and I changed it to 1.8 and it stopped complaining about java version.
if you use sqldeveloper 18.2.0
edit %APPDATA%\sqldeveloper\18.2.0\product.conf
jdk9, jdk10, and jdk11 are not supported
change back to jdk 8
for example
SetJavaHome C:\Program Files\ojdkbuild\java-1.8.0-openjdk-1.8.0.191-1
A couple of months back I added a SSL cert in JRE's trustcacerts for avoiding not-a-valid-certificate issues.
There I imported the self signed certificate to the following file
"C:\Program Files\Java\jre6\lib\security\cacerts"
Question 1
But now when I am trying to access to this file it's not available and instead when I go to
"C:\Program Files\Java\jre6\lib"
I can find only one folder named ext and inside it a Zipped file named QTJava
Wonder what have happened to the files which were there under Java 6.
Question 2.
And also when I opened the Windows command Prompt in Admin mode and try to use keytool command in there it says
"C:\Program Files\Java\jre7\lib\security\cacerts"
'keytool' is not recognized as an internal or external command,
operable program or batch file.
I Would like to know if someone knows a way to get this done.
Q1: It seems fine on my system using the latest JRE, so I think your install is borked.
Q2: That's easy, add your JDK or JRE bin folder to the PATH environment variable. Normally something like set PATH="%PATH%;%JAVA_HOME%/bin" should do it (given that your JAVA_HOME variable points to your JDK or JRE installation folder).
Q1 : Installation may be corrupt
Q2 : Add your java/bin to your PATH variable.
PATH="%PATH%;%JAVA_HOME%/bin"
For this to work, You need to have JAVA_HOME variable set in your environment pointing to your JDK installation directory