1
votes

This is my bash script ("compile_java.sh"):

#!/bin/bash
filename=$(basename -- "$1")
extension="${filename##*.}"
filename="${filename%.*}"
echo "$1"
echo "$filename"
echo "$extension"
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:15 javac $1

And that is my try to call the bash script (i'm using Ubuntu): . compile_java.sh TestJava.java

And that is the "error" message:

TestJava.java
TestJava
java
error: invalid flag: TestJava.java
Usage: javac <options> <source files>
use --help for a list of possible options

Can someone give me a hint please?

1
you need to set java path - Digvijay S
@DigvijayS that isn't working for me: export JAVA_HOME=/usr/lib/jvm/openjdk-15-jdk export PATH=$PATH:$JAVA_HOME/bin docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:15 javac $1 - CyborgBeta

1 Answers

-1
votes

Sorry, there was special characters in the bash file. This works fine:

docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:15 javac $1