Prepare Docker appropriately.
FROM java:9
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", "Main"]
It seems that takeWhile
has been newly introduced.
It's been a while since I touched Java, but it's interesting because it's different.
import java.util.stream.Stream;
public class Main {
static public void main(String[] args) {
Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.takeWhile(i -> i < 5)
.forEach(System.out::println);
}
}
I will do it.
$ docker build -t my-java-app .
$ docker run -it --rm --name my-running-app my-java-app
1
2
3
4
Sounds good.
I will also try jshell.
$ docker run -it my-java-app jshell
It will be complemented and you can try it right away. It is still convenient to have a REPL.
Recommended Posts