Java bash: jar: 命令未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23538864/
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
bash: jar: command not found
提问by Satish
I'm using Jenkinsto deploy the build.
我正在使用Jenkins来部署构建。
We need to extract files from a .warinto some directory. We have an .xmlfile which includes commands to extract the files from the .warfile and start the server.
我们需要将.war 中的文件提取到某个目录中。我们有一个.xml文件,其中包含从.war文件中提取文件并启动服务器的命令。
The build is being created properly but the .warextraction is not happening and the destination folder is being left empty. The Jenkins Console shows the following output:
构建正在正确创建,但.war提取没有发生,目标文件夹被留空。Jenkins 控制台显示以下输出:
[sshexec] bash: jar: command not found
As read from other answers, I have set the PATH
properly in .bashrcor in .profilebut I'm still facing the same issue.
从其他答案中读到,我已经PATH
在.bashrc或.profile 中正确设置了,但我仍然面临同样的问题。
回答by Keerthivasan
To be specific, JAVA
bin directory is not in your PATH
variable. Add it to PATH
variable. In order to search the executables, the OS need to have a list of directories to look up. So, Add the directory which contains 'jartool in the
PATH` environment variable
具体来说,JAVA
bin 目录不在您的PATH
变量中。将其添加到PATH
变量中。为了搜索可执行文件,操作系统需要有一个要查找的目录列表。因此,添加包含“jar tool in the
PATH”环境变量的目录
Note : For Windows, Path separator is (;
) and for Unix-like OS, Path separator is (:
)
注意:对于 Windows,路径分隔符是 ( ;
) 而对于类 Unix 操作系统,路径分隔符是 ( :
)
回答by sti
The "[sshexec]" tells me you are using some Jenkins plugin to execute a command on a remote host.
“[sshexec]”告诉我您正在使用一些 Jenkins 插件在远程主机上执行命令。
This usually means Jenkins executes this (or an equivalent thing by implementing the SSH protocol natively):
这通常意味着 Jenkins 执行此操作(或通过本地实现 SSH 协议来执行等效操作):
ssh user@remotehost 'jar arg1 arg2...'
What happens here is the sshd daemon on the remote host will execute the default shell of the user and ask the shell to execute the command line. The shell is typically not executed as a "login shell", meaning the shell will skip the initialization steps that login shells normally do when the user logs in interactively.
这里发生的是远程主机上的 sshd 守护进程将执行用户的默认 shell 并要求 shell 执行命令行。shell 通常不作为“登录 shell”执行,这意味着当用户交互登录时,shell 将跳过登录 shell 通常执行的初始化步骤。
You can study man (name of your shell)
to see exactly what the difference is between a shell executed with -l
option and one executed without it. In the case of bash it essentially means .profile
and .bashrc
will not be executed, so any PATH modifications you might have there will not take place.
您可以研究man (name of your shell)
以查看使用-l
option执行的 shell和没有它执行的 shell 之间的区别。在 bash 的情况下,它本质上意味着.profile
并且.bashrc
不会被执行,因此您可能在那里进行的任何 PATH 修改都不会发生。
I think your best bet is to provide the full path to the jar
command when you want to execute it.
我认为你最好的办法是jar
在你想要执行它时提供命令的完整路径。
回答by Smartop
Install Java devel as follows:
安装Java开发如下:
yum install java-devel
回答by Ajit K'sagar
As you are executing the command on remote host so, it will invoke the new Shell on the remote host. The PATH which you have set in the current host .bashrc file will not make any difference. Instead if you set the PATH for Java in remote host's .bashrc things should work else if you are running any script then mention the complete path for JAR like /usr/jdk64/jdk1.8.0_40/bin/jar -tf /tmp/jars/abc.jar while invoking the command on remote host.
当您在远程主机上执行命令时,它将调用远程主机上的新 Shell。您在当前主机 .bashrc 文件中设置的 PATH 不会有任何区别。相反,如果您在远程主机的 .bashrc 中为 Java 设置 PATH,那么如果您正在运行任何脚本,那么事情应该可以正常工作,然后提及 JAR 的完整路径,如 /usr/jdk64/jdk1.8.0_40/bin/jar -tf /tmp/jars /abc.jar 在远程主机上调用命令时。
Two ways to do:
两种做法:
export PATH=$PATH:/usr/jdk64/jdk1.8.0_40/bin ---> in remote host's .bashrc
/usr/jdk64/jdk1.8.0_40/bin/jar -tf /tmp/jars/abc.jar --> invoke the jar command with complete path for JAR from remote host.
export PATH=$PATH:/usr/jdk64/jdk1.8.0_40/bin ---> 在远程主机的 .bashrc
/usr/jdk64/jdk1.8.0_40/bin/jar -tf /tmp/jars/abc.jar --> 从远程主机调用带有 JAR 完整路径的 jar 命令。