使用 "java" 命令运行 .jar 文件 Centos
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2929465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run .jar file with "java" command Centos
提问by Jorre
I'm trying to run a .jar file on my centos box, but it says "java: command not found".
我正在尝试在我的 centos 机器上运行一个 .jar 文件,但它显示“java:找不到命令”。
What's the best or easiest way to solve this? I was hoping for a yum command but not sure that that will exist for java?
解决这个问题的最好或最简单的方法是什么?我希望有一个 yum 命令,但不确定 java 是否存在该命令?
回答by Bill the Lizard
Apparently some versions of CentOS doesn't come with a JVM installed due to some licensing restriction. See HowTo Install Java on CentOS 4 and CentOS 5for instructions.
显然,由于某些许可限制,某些版本的 CentOS 没有安装 JVM。有关说明,请参阅如何在 CentOS 4 和 CentOS 5 上安装 Java。
回答by Lukasz Stelmach
You can use such command to check if Java is available in your repository:
您可以使用这样的命令来检查您的存储库中是否有 Java:
yum list | grep java
It should return something like that:
它应该返回类似的东西:
java-1.6.0-openjdk
java-1.6.0-sun
If such package exists you can install it using such command (run it as the root user):
如果存在这样的包,您可以使用这样的命令安装它(以 root 用户身份运行):
yum install java-1.6.0-openjdk
回答by Syntactic
Either the JRE is not installed or, more likely, its location is not included in your PATHenvironment variable. If the javaexecutable is not in your PATH, you would need to use the full path & filename to execute it.
JRE 未安装,或者更有可能的是,它的位置未包含在您的PATH环境变量中。如果java可执行文件不在您的PATH.
回答by randomguy
cd to the location of the jar file
cd到jar文件所在的位置
C:\temp>java -jar sample.jar
C:\temp>java -jar sample.jar

