Java and JUnit and Docker

  • Java
    • JDK JVM SDK JRE
    • IntelliJ
      • Download openJdk-15.0.1
      • Creating console application
      • Creating a JUnit test
      • Running the JUnit test
    • JUnit
    • class path
    • javac.exe (compile from command line)
      • javac – version
      • “C:\Program Files\Java\jdk1.8.0_281\bin\javac.exe” <file-name>.java
      • “C:\Program Files\Java\jdk1.8.0_281\bin\javac.exe” <file-name>.java -cp .;”<jar1-location.jar>”;”<jar2-location.jar>”
    • java (running junit from console):
      • java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore Exampletest
      • (make sure the: junit-4.12.jar , hamcrest-core-1.3.jar are in the same folder)
      • (Exampletest should be a .class file which was compiled with javac [Exampletest.java originally])
  • Docker
    • what is docker?
    • how to install docker on Windows and Linux
    • what is docker image
    • what is docker container
    • docker hub repository
    • docker desktop for Windows
    • docker commands:
      • docker version
      • docker run <image-name> [download and run image]
      • docker run docker/whalesay cowsay hello-world
      • docker ps [show running containers]
      • docker ps -a [show container history]
      • docker images [show image]
      • docker rmi <image-name> -f [force remove image]
      • docker pull <image-name> [will download the image]
    • Dockerfile
    • docker is not a vm! it is task-purposed!

How to build and run JUnit in a command line:

Open a folder and make sure to create the following files:

  • download and copy junit-4.12.jar file into the same folder
  • download and copy hamcrest-core-1.3.jar file into the same folder
  • “C:\Program Files\Java\jdk1.8.0_281\bin\javac.exe” Example.java ExampleTest.java -cp .;junit-4.12.jar
  • (assuming you are using javac.exe from jdk1.8, check it by: javac -version)
  • java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore Exampletest
  • (assuming you are using java.exe from jdk1.8, check it by: java -version)

How to install docker on CentOS:

first option-

  • $ sudo yum install -y yum-utils
  • $ sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • $ sudo yum install docker-ce docker-ce-cli containerd.io
  • $ yum list docker-ce –showduplicates | sort -r
    • CHOOSE YOUR HIGHEST VERSION AND RUN
    • i.e. if you got this: docker-ce.x86_64 3:18.09.1-3.el7
    • so run- $ sudo yum install docker-ce-18.09.1 docker-ce-cli-18.09.1 containerd.io
    • TROUBLESHOOT: $ yum erase podman buildah
  • $ sudo systemctl start docker
  • $ sudo docker run hello-world

second option-

  • $ curl -fsSL https://get.docker.com -o get-docker.sh
  • $ sudo sh get-docker.sh
  • $ sudo systemctl start docker
  • $ sudo docker run hello-world

Links:

Homework:

  • Install IntelliJ community edition
  • Install openjdk-15.0.1 (do it inside IntelliJ)
  • Install docker inside the CentOS virtual-box

Lab assignment:

Leave a comment