简体   繁体   中英

Run java in $PATH as an interpreter

I want to make a script starting with a line:

#!java hogehoge.Hoge

In my machines of OS X and CentOS7, it runs.

But machines of CentOS6 give me an error:

./test.sh: bad interpreter: java

(My OS is JP so I omitted some of error messages but anyway it says java does not exist.)

All the environments are under zsh and of course, every $PATH contains a certain PATH like /usr/bin. If I try a new script starting with:

#!/usr/bin/java hoge.Hoge

then it runs even in where the script with "java" does not work.

Does the difference come from the one between OSs?

or is there anything else that I do not realize?

Java isn't a script interpreter, but you can run your java process with a script. Something like

#!/usr/bin/env bash
# export JAVA_HOME="/path/to/java_installation"
# export PATH="$PATH:$JAVA_HOME/bin"
java hoge.Hoge

You may need to define JAVA_HOME and add it to your PATH (depending on your installation of Java).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM