英文:
javac is not recognized as internal command
问题
我的当前系统配置是 -
- Netbeans 12.0
- JDK 14.0.2
- Windows 10 (64位)
-
我手动将环境变量添加到PATH中,即C:\Program Files\Java\jdk-14.0.2\bin。
-
我尝试使用命令行添加,同时将JAVA_HOME作为一个新变量添加,其值为C:\Program Files\Java\jdk-14.0.2。
-
我使用set命令来执行此过程,即set path="%path%;C:\Program Files\Java\jdk-14.0.2\bin"。此外,我还尝试过不使用set关键字的相同命令。
-
由于javah命令在jdk>8的版本中已被弃用,我也尝试使用javac -h命令。
-
我还尝试安装了JDK v. 8.0.2,而不是当前的版本。
-
尽管bin文件夹中没有javah.exe文件,但有javac.exe文件。
-
我已经多次卸载并重新安装了JDK和Netbeans。
我目前正在使用Netbeans IDE和C/C++插件进行JNI开发(我已成功安装了Cygwin和必要的文件扩展以进行构建。虽然我不知道它们如何影响这个问题,但我认为我应该添加这一点)。
我希望与'javah'一起使用的命令是从Java类创建C头文件的命令,即'javah -o JNIDemoJava.h -classpath JNIDemoJava/build/classes jnidemojava.Main'。
但由于这个错误,我已经卡住了几天。请协助解决。
英文:
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.
答案1
得分: 1
以下是翻译好的部分:
以下是您可以设置路径变量的临时方式(仅可在相同的命令行中使用):
您应该这样做:(注意 =)
set PATH=C:\Program Files\Java\jdk-14.0.2\bin
如果您已正确设置了JAVA_HOME变量,可以这样做:
set PATH="%JAVA_HOME%\bin"
要永久设置此项,请阅读此帖子:
https://javatutorial.net/set-java-home-windows-10
英文:
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 :
答案2
得分: 0
我们应该知道这个原因:
-
我们的操作系统带有一组预定义的工具和实用程序。当我们尝试在Windows命令行中执行命令
e.g. cls
时,它已经存在于系统路径变量中,操作系统将引用相应的cls
二进制文件来执行该命令。 -
然而,当我们安装任何第三方工具/软件时,路径变量不会相应地更新。
-
当我们在系统上安装不同版本的Java时,安装将在不同的目录中进行。例如,Windows上的JDK安装目录将是
C:\Program Files\Java\jdk1.8.0_161
。 -
类似地,Windows上的JRE安装目录将是JDK安装目录的子目录:
C:\Program Files\Java\jre1.8.0_161
-
我们需要更新操作系统的路径变量,以指向适当的目录。如果我们设置了JDK的路径,它将执行JDK bin目录中的二进制文件。
解决方案
- 我们需要将
JDK
或JRE
特定版本的目录位置更新到PATH
环境变量中。 - 在这种情况下,使用以下命令来设置JAVA_PATH:
set path=C:\Program Files\Java\jdk-14.0.2\bin
英文:
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 ofcls
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
orJRE
version specific directory location intoPATH
Environment variable. - In this case use
set path=C:\Program Files\Java\jdk-14.0.2\bin
to set JAVA_PATH
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论