I am working on a docker image which I need to install sbt1.8.2. I downloaded the sbt1.8.2.zip file and unzip it, however while checking the version of sbt using sbtVersion, java is missing even though I declared the JAVA_HOME.
This is my sample dockerfile:
ENV SBT_VERSION=1.8.2
ENV JAVA_VERSION=1.8.0_60
ENV JAVA_HOME /opt/jdk${JAVA_VERSION}/jre/
# Install SBT
RUN curl -L -o sbt-$SBT_VERSION.zip download/internal/url/sbt-1.8.2.zip
RUN unzip -o sbt-$SBT_VERSION.zip -d /opt/
CMD /opt/sbt/bin/sbt run \
sbt sbtVersion
This is my sample bats file for testing.
#!/usr/bin/env bats
load $(pwd)/helpers/sdp-helper.bash
#test "SBT Version" {
EXPVER="1.8.2"
run ${dockerRun} bash -c "JAVA_HOME=/opt/jdk1.8.0_60/jre /opt/sbt/bin/sbt sbtVersion"
sdp::outCmd2Tap
[[ ${status} -eq 0 ]]
[[ ${lines[0]} =~ "${EXPVER}" ]]
}
Error:
/opt/sbt/bin/sbt: line 460: java: command not found
copying runtime jar...
mkdir: cannot create directory '': No such file or directory
/opt/sbt/bin/sbt: line 467: java: command not found
/opt/sbt/bin/sbt: line 229: exec: java: not found
My bash version
$ bash --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)
My java version
$ java --version
openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
My kotlinc version
$ kotlinc -version
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
info: kotlinc-jvm 1.3.50 (JRE 13.0.1+9)
What I tried
$ echo *
chap_six.kt clean.sh hello.jar hello.kt README.md start.sh
$ echo \*
*
My simple print program
// hello.kt
fun main(args: Array<String>) {
println(args[0])
}
After compiling my simple print program
kotlinc hello.kt -include-runtime -d hello.jar
I expect to see the * symbol printed in the console when running the java .jar
Here's what I get
$ java -jar hello.jar *
chap_six.kt
$ java -jar hello.jar \*
.git
$ java -jar hello.jar "*"
.git
$ java -jar hello.jar "\*"
\$Recycle.Bin
I tried to apply what is suggested in this answer but it failed too
My hello.sh
#!/bin/bash
FOO="*"
set +f
GLOBIGNORE=*
java -jar hello.jar $FOO
and the attempt
$ ./hello.sh
.git
My hello2.sh also fails
#!/bin/bash
FOO="*"
set -f
java -jar hello.jar $FOO
And the attempt
$ ./hello2.sh
.git
My shopt looks like this
$ shopt
autocd off
cdable_vars off
cdspell off
checkhash off
checkjobs off
checkwinsize off
cmdhist on
compat31 off
compat32 off
compat40 off
compat41 off
compat42 off
compat43 off
completion_strip_exe off
complete_fullquote on
direxpand off
dirspell off
dotglob off
execfail off
expand_aliases on
extdebug off
extglob off
extquote on
failglob off
force_fignore on
globasciiranges off
globstar off
gnu_errfmt off
histappend off
histreedit off
histverify off
hostcomplete on
huponexit off
inherit_errexit off
interactive_comments on
lastpipe off
lithist off
login_shell off
mailwarn off
no_empty_cmd_completion off
nocaseglob off
nocasematch off
nullglob off
progcomp on
promptvars on
restricted_shell off
shift_verbose off
sourcepath on
xpg_echo off
My set -o looks like this
$ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
igncr off
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace off
Not a solution but a mean to frame the source of the issue.
Lets create hello.sh in Bash to compare how it handles the arguments array.
#!/usr/bin/env bash
# hello.sh
echo "$1"
Now create a test.sh to compare the output of same hello in Kotlin and Bash:
#!/usr/bin/env bash
for arg in '*' '\*' "'*'" '"*"'; do
kotlinout="$(java -jar hello.jar $arg)"
bashout="$(bash hello.sh $arg)"
if [ "$kotlinout" = "$bashout" ]; then
comp='are same';
else
comp='DIFFERS !!'
fi
printf 'Argument: %s\tKotink and Bash outputs %s\n' "$arg" "$comp";
printf 'Kotlin output: %s\n' "$kotlinout";
printf 'Bash output: %s\n' "$bashout";
done
Here is what it does in my environment:
$ bash test.sh
Argument: * Kotink and Bash outputs are same
Kotlin output: chap_six.kt
Bash output: chap_six.kt
Argument: \* Kotink and Bash outputs are same
Kotlin output: \*
Bash output: \*
Argument: '*' Kotink and Bash outputs are same
Kotlin output: '*'
Bash output: '*'
Argument: "*" Kotink and Bash outputs are same
Kotlin output: "*"
Bash output: "*"
From this repository
I try to run this step
./PersonalityRecognizer -i ../output_dir -d -t 2 -a ../mairesse_Apache.arff
but I receive this error
$ ./PersonalityRecognizer -i ../output_dir -d -t 2 -a ../mairesse_Apache.arff
./PersonalityRecognizer: line 15: ../../apps/jdk1.5.0_05/bin/java: No such file or directory
How can I proceed? Which file or directory is not?
Into the instructions they refer this:
Open the file PersonalityRecognizer (or PersonalityRecognizer.bat if
you're using Windows) and edit the variable JDK_PATH with the full
path to the root of your Java installation.
So here is the file which I made the change:
#echo off
rem WINDOWS LAUNCH SCRIPT
rem ENVIRONMENT VARIABLES TO MODIFY
set JDK_PATH="C:\ProgramData\Oracle\Java\javapath"
set WEKA="H:\apps\weka-3-4\weka.jar"
rem ----------------------------------
set COMMONS_CLI="lib\commons-cli-1.0.jar"
set JMRC="lib\jmrc.jar"
set LIBS=%WEKA%;%COMMONS_CLI%;%JMRC%;%CD%;bin\
%JDK_PATH%\bin\java -Xmx512m -classpath %LIBS% recognizer.PersonalityRecognizer %1 %2 %3 %4 %5 %6 %7 %8 %9
However if I run this in cmd to check for java I receive this one:
C:\Users\Nathalie>which java
/c/ProgramData/Oracle/Java/javapath/java
What can I do?
I created a docker image from openjdk:8-jdk-alpine using the below Dockerfile:
But when I try to execute simple commands I get the following errors:
/bin/sh: ./run.sh: not found
my run.sh looks like this
enter image description here
I try to "docker run -it [images] bash" enter to the interactive environment,I can see the file "run.sh".In the directory /bin bash exist,but I execute run.sh also display " /bin/sh: ./run.sh: not found"
PS:Sorry for my poor english,I am a chinese student
The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.
Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.
Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.
I then converted the run.sh to use dos line endings and got the following:
$ file run.sh
run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
$ docker run --rm -it bob
/bin/sh: ./run.sh: not found
Which looks suspiciously like your error message.
From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.
how to convert the line endings (some examples):
dos2unix run.sh
perl -pi -e 's/\r\n/\n/g' run.sh
Previous Answer
The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.
On alpine, bash is installed into /bin, so if you try to run the script you will see the error:
/ # ./run.sh
/bin/sh: ./run.sh: not found
/ # cat run.sh
#!/usr/bin/bash
echo "Hi"
workaround (1): after the apk add bash, do an:
RUN ln -s /bin/bash /usr/bin
in your Dockerfile. This will create a symlink for bash, allowing the program to run:
/ # ln -s /bin/bash /usr/bin
/ # ./run.sh
Hi
workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -
CMD [ 'bash', './run.sh' ]
I want to create a script (foo.sh) such as:
#!/bin/sh
set -o posix
. setpath.sh
java foo.Bar "$#"
and I want to use like:
./foo.sh -p -o -ff filename
but the shell returns an error message. illegal option
if I launch
java foo.Bar -p -o -ff filename
then it works.
How can create a script for that?
I guess
. setpath.sh
has problem..
If I change it to
. setpath.sh --
then
./foo.sh -anyoptoptions
works...
but I have quite no idea what happens...