# JAVA18

jwebserver 구동

공식사이트에서 캡처 이미지를 이용해보겠다.

<figure><img src="/files/I2EJv1I8lVjy4TtqpHVe" alt=""><figcaption></figcaption></figure>

짧은 영어능력으로 일단 이해한 내용을 요약하면!

* Jetty、Nginx 등 기존 웹서버를 대체하기위함이 아닌 순수 테스트,학습목적으로 만들어 졌다.
* 인증, 시큐리티, 액세스컨트롤, 암호화 등 기능은 지원하지 않는다.
* HTTP/1.1 만 지원하고 HTTPS는 지원 안한다!
* GET、HEAD 요청만 지원한다.
* 명령을 통한 Java 클래스 구동이 가능하다.

아주 간단한 index.html  파일하나 만들어보자!

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
    <h1>안녕하세요 신비한 비 티스토리 블로그 입니다!</h1>
    </div>
    <div><h3>티스토리블로그:</h3></div>
    <url>https://rainsister.tistory.com/</url>
    <div><h3>깃북블로그:</h3></div>
    <url>https://app.gitbook.com/o/oa8n0se1zcxXR1QCxPlj/home</url>
    
</body>
</html>
```

내가 설치한 java 버전 그리고 home 경로를 파악해보자. 맥 기준 터미널에서

```bash
/usr/libexec/java_home -V
Matching Java Virtual Machines (7):
    18.0.2.1 (x86_64) "Eclipse Adoptium" - "OpenJDK 18.0.2.1" /Users/blake/Library/Java/JavaVirtualMachines/temurin-18.0.2.1/Contents/Home
    17.0.5 (arm64) "Eclipse Adoptium" - "OpenJDK 17.0.5" /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
    16.0.2 (x86_64) "Eclipse Temurin" - "Eclipse Temurin 16" /Library/Java/JavaVirtualMachines/temurin-16.jdk/Contents/Home
    11.0.17 (arm64) "Eclipse Adoptium" - "OpenJDK 11.0.17" /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
    11.0.11 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    1.8.0_345 (x86_64) "Eclipse Temurin" - "Eclipse Temurin 8" /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
    1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
```

/Users/blake/Library/Java/JavaVirtualMachines/temurin-18.0.2.1/Contents/Home 로 확인 인된다.

jwebserver 를 시작하기 위해 bin 폴더까지 이동한다.

```
./jwebserver
Binding to loopback by default. For all interfaces use "-b 0.0.0.0" or "-b ::".
Serving /Users/blake/Library/Java/JavaVirtualMachines/temurin-18.0.2.1/Contents/Home/bin and subdirectories on 127.0.0.1 port 8000
URL http://127.0.0.1:8000/
127.0.0.1 - - [05/1월/2023:16:16:31 +0900] "GET /index.html HTTP/1.1" 200 -
127.0.0.1 - - [05/1월/2023:16:16:59 +0900] "GET /index.html HTTP/1.1" 200 -
```

추가 설명!

```bash
-h or -? or --help
 Prints the help message and exits.

-b addr or --bind-address addr
 Specifies the address to bind to.  Default: 127.0.0.1 or ::1 (loopback).  For
 all interfaces use -b 0.0.0.0 or -b ::.

-d dir or --directory dir
 Specifies the directory to serve.  Default: current directory.

-o level or --output level
 Specifies the output format.  none | info | verbose.  Default: info.

-p port or --port port
 Specifies the port to listen on.  Default: 8000.

-version or --version
 Prints the version information and exits.
```

* `-b`：바인딩할 ip
* `-p`：포트
* `-d`：제공할 목록&#x20;
* `-o`：console 출력등급

```bash
jwebserver -p 9000 -d / -b 127.0.0.1 -o info
```

<figure><img src="/files/UTfm1ZagdBWDVd1SIQPN" alt=""><figcaption></figcaption></figure>

\
루트 / 디렉토리의 내용을 확인 할수 있다.

## jwebserver 구동(with java code)

테스트용 메인함수 하나 만든다.

```java
public static void main(String[] args) {
    System.out.println("구동완료!!!");
    
    var addr = new InetSocketAddress(9898);
    var server = SimpleFileServer.createFileServer(
        addr, Path.of("/"), SimpleFileServer.OutputLevel.INFO);
    server.start();
}
```

<figure><img src="/files/7nrPnZO5qGgd8Cjh8jHr" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/S7gZl3xCODIx8PDj5Rpa" alt=""><figcaption></figcaption></figure>

확인을 위해 9898 포트 새로 띄여보면 정상적으로 시작된걸 알수 있다.

끝!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blakes-organization.gitbook.io/rainsister/java/java18.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
