-
Notifications
You must be signed in to change notification settings - Fork 8
/
tryJava.sh
executable file
·46 lines (38 loc) · 1.51 KB
/
tryJava.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
###################################################
#### ---- Change this only if want to use your own
###################################################
ORGANIZATION=openkbs
###################################################
#### ---- Container package information ----
###################################################
DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" `
imageTag=${1:-"${ORGANIZATION}/${DOCKER_IMAGE_REPO}"}
instanceName=some-jdk-mvn-py3
function cleanup() {
if [ ! "`docker ps -a|grep ${instanceName}`" == "" ]; then
docker rm -f ${instanceName}
fi
}
mkdir -p ./data
mkdir -p ./data
cat >./data/HelloWorld.java <<-EOF
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
EOF
cat ./data/HelloWorld.java
djavac='docker run -it --rm -v '$PWD'/data:/data --workdir /data '${imageTag}' javac'
djava='docker run -it --rm -v '$PWD'/data:/data --workdir /data '${imageTag}' java'
echo
echo "----------------------------------------------------------------------"
echo "1.) Compile HelloWorld.java in Guest's workdir /data: "
echo "docker run -it --rm -v $PWD/data:/data --workdir /data ${imageTag} javac HelloWorld.java"
$djavac HelloWorld.java
echo
echo "----------------------------------------------------------------------"
echo "2.) Run HelloWorld.class in Guest's workdir /data: "
echo "docker run -it --rm -v $PWD/data:/data --workdir /data ${imageTag} java HelloWorld"
$djava HelloWorld