“java。exe不被识别为内部或外部命令、可操作程序或批处理文件。

时间:2021-02-10 23:13:27

I am writing an application that creates a Java portlet by the ant batch file with the cmd.exe using a Process object in C#.

我正在编写一个应用程序,该应用程序通过与cmd的ant批处理文件创建Java portlet。使用c#中的进程对象执行exe。

When I pass the "Create" command to the cmd to create portlet, I receive an error like this:

当我将“Create”命令传递给cmd以创建portlet时,我收到这样的错误:

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

But when I type this command on the cmd directly, that works correctly.

但是当我直接在cmd上键入这个命令时,它就能正常工作了。

I've installed the JDK on my windows 7 and set the JAVA_HOME and ANT_HOME variables in the Environment Variables. Can you help me to correct that?

我在windows 7上安装了JDK,并在环境变量中设置了JAVA_HOME和ANT_HOME变量。你能帮我改正吗?

7 个解决方案

#1


3  

You should check your PATH variable. You can use the set command to set the correct path to your java environment folder.

应该检查路径变量。您可以使用set命令来设置java环境文件夹的正确路径。

#2


2  

I don't know if this will help anyone else that is viewing this post but when i had this problem it was because I was running a x64 machine and the java.exe was installed to the ProgramFiles(x86) folder. I simply added the path to the exe to the 'PATH' environment variable and then it fired up just fine.

我不知道这是否会帮助其他人查看这个帖子,但是当我遇到这个问题的时候,因为我运行的是x64机器和java。exe被安装到ProgramFiles(x86)文件夹中。我只是将exe的路径添加到“path”环境变量中,然后它就启动了。

Hope this helps someone.

希望这可以帮助别人。

#3


1  

try setting tha java path properly

尝试正确设置java路径

can u give me the exact error message u get...

你能给我准确的错误信息吗?

#4


1  

In my experience, this problem had nothing to do with Java path. Actually I had installed java for 64 bit machine and had compiled my C# program with 32 bit settings. Calling a 64Bit program was not possible from a 32bit program. So i changed my Target platform to "Any CPU" and it worked fine.

在我的经验中,这个问题与Java路径无关。实际上,我已经为64位机安装了java,并编译了带有32位设置的c#程序。在32位程序中不可能调用64位程序。所以我把目标平台改成了“任意CPU”,它运行得很好。

#5


0  

I also ran into the same problem and found my solution. It might help you too.

我也遇到了同样的问题,找到了解决办法。这可能对你也有帮助。

  1. Set the PATH variable. I don't know if this step is required or not, but i just added the path to java.exe in TEMP variable.
  2. 设置PATH变量。我不知道这个步骤是否需要,但我只是添加了java的路径。exe在临时变量中。
  3. At command prompt changed the current directory to java.exe parent directory.
  4. 在命令提示符下,将当前目录更改为java。exe父目录。
  5. Now ran to command which i required. If some file is been referenced in the command then i put the complete path.
  6. 现在执行我所要求的命令。如果某个文件在命令中被引用,那么我将放置完整的路径。

Hope it helps you.

希望它能帮助你。

#6


0  

If you have multiple values in your PATH variable, make sure they are not separated with a space following the end semi-colon (;)

如果路径变量中有多个值,请确保它们与结束分号(;)后面的空格分隔

#7


0  

I had the same problem and solved it. I'm using 64-bit Windows 7 with 64-bit Java. Setting the compile target in the Configuration Manager to 'x64' solved it. If you use 'any CPU' the build probably falls back to 'x86', which is not working with 64-bit Java. So you need different builds for different machines...

我遇到了同样的问题并解决了它。我正在使用64位Windows 7和64位Java。将配置管理器中的编译目标设置为“x64”解决。如果您使用“任何CPU”,构建可能会回到“x86”,这与64位Java不兼容。因此,对于不同的机器,您需要不同的构建……

#1


3  

You should check your PATH variable. You can use the set command to set the correct path to your java environment folder.

应该检查路径变量。您可以使用set命令来设置java环境文件夹的正确路径。

#2


2  

I don't know if this will help anyone else that is viewing this post but when i had this problem it was because I was running a x64 machine and the java.exe was installed to the ProgramFiles(x86) folder. I simply added the path to the exe to the 'PATH' environment variable and then it fired up just fine.

我不知道这是否会帮助其他人查看这个帖子,但是当我遇到这个问题的时候,因为我运行的是x64机器和java。exe被安装到ProgramFiles(x86)文件夹中。我只是将exe的路径添加到“path”环境变量中,然后它就启动了。

Hope this helps someone.

希望这可以帮助别人。

#3


1  

try setting tha java path properly

尝试正确设置java路径

can u give me the exact error message u get...

你能给我准确的错误信息吗?

#4


1  

In my experience, this problem had nothing to do with Java path. Actually I had installed java for 64 bit machine and had compiled my C# program with 32 bit settings. Calling a 64Bit program was not possible from a 32bit program. So i changed my Target platform to "Any CPU" and it worked fine.

在我的经验中,这个问题与Java路径无关。实际上,我已经为64位机安装了java,并编译了带有32位设置的c#程序。在32位程序中不可能调用64位程序。所以我把目标平台改成了“任意CPU”,它运行得很好。

#5


0  

I also ran into the same problem and found my solution. It might help you too.

我也遇到了同样的问题,找到了解决办法。这可能对你也有帮助。

  1. Set the PATH variable. I don't know if this step is required or not, but i just added the path to java.exe in TEMP variable.
  2. 设置PATH变量。我不知道这个步骤是否需要,但我只是添加了java的路径。exe在临时变量中。
  3. At command prompt changed the current directory to java.exe parent directory.
  4. 在命令提示符下,将当前目录更改为java。exe父目录。
  5. Now ran to command which i required. If some file is been referenced in the command then i put the complete path.
  6. 现在执行我所要求的命令。如果某个文件在命令中被引用,那么我将放置完整的路径。

Hope it helps you.

希望它能帮助你。

#6


0  

If you have multiple values in your PATH variable, make sure they are not separated with a space following the end semi-colon (;)

如果路径变量中有多个值,请确保它们与结束分号(;)后面的空格分隔

#7


0  

I had the same problem and solved it. I'm using 64-bit Windows 7 with 64-bit Java. Setting the compile target in the Configuration Manager to 'x64' solved it. If you use 'any CPU' the build probably falls back to 'x86', which is not working with 64-bit Java. So you need different builds for different machines...

我遇到了同样的问题并解决了它。我正在使用64位Windows 7和64位Java。将配置管理器中的编译目标设置为“x64”解决。如果您使用“任何CPU”,构建可能会回到“x86”,这与64位Java不兼容。因此,对于不同的机器,您需要不同的构建……