Added lesson2
commit
bcdb5c0ab3
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "Core_JAVA_Volume1"]
|
||||||
|
path = Core_JAVA_Volume1
|
||||||
|
url = git@github.com:specter01wj/Core_JAVA_Volume1.git
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 8ca9c76bf17e49e0d4654973fff7889caf4644e8
|
|
@ -0,0 +1,5 @@
|
||||||
|
FROM openjdk:slim-buster
|
||||||
|
COPY Core_JAVA_Volume1/corejava/v1ch02/ImageViewer /usr/src/myapp
|
||||||
|
WORKDIR /usr/src/myapp
|
||||||
|
RUN javac ImageViewer.java
|
||||||
|
CMD ["java", "ImageViewer"]
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Lesson 2: The Java Programming Environment
|
||||||
|
|
||||||
|
## Run as server
|
||||||
|
|
||||||
|
For headless application (run as server), we can use docker.
|
||||||
|
|
||||||
|
After create `FILE.java`, create a `Dockerfile`
|
||||||
|
|
||||||
|
```
|
||||||
|
FROM openjdk:slim-buster
|
||||||
|
COPY <script location> /usr/src/myapp
|
||||||
|
WORKDIR /usr/src/myapp
|
||||||
|
RUN javac <script>.java
|
||||||
|
CMD ["java", "<script name>"]
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run and build the Docker image
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker build -t my-java-app .
|
||||||
|
$ docker run -it --rm --name my-running-app my-java-app
|
||||||
|
```
|
||||||
|
|
||||||
|
## If run as desktop application
|
||||||
|
|
||||||
|
First, compile Java
|
||||||
|
|
||||||
|
```
|
||||||
|
$ javac <script>.java
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, run Java
|
||||||
|
|
||||||
|
```
|
||||||
|
$ java <script>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run jshell for interaction
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
|
||||||
|
* 1: `$ jshell`
|
||||||
|
* 2: using docker: `docker run --rm -it -v "$(pwd)":/usr/src openjdk:slim-buster`
|
Loading…
Reference in New Issue