|
1 | 1 | # GitHub Codespaces ♥️ Java |
2 | 2 |
|
3 | | -This repository is a weather app built on the JDK 25 built-in HTTP server. |
| 3 | +Want to try out Java for web development? |
4 | 4 |
|
5 | | -It serves: |
6 | | -- a REST API at `/api/weatherforecast` |
7 | | -- static frontend assets (`index.html`, CSS, JavaScript) |
| 5 | +This repo builds a Weather API and a web frontend in a single Java project using the JDK 25 built-in HTTP server (`jdk.httpserver`). |
8 | 6 |
|
9 | | -## Run |
| 7 | +You get both backend and frontend in one place, and where you go from here is up to you. |
10 | 8 |
|
11 | | -1. Compile: |
| 9 | +Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it’s gone forever. |
12 | 10 |
|
13 | | - mvn compile -f sample-app/pom.xml |
| 11 | +### Run Options |
14 | 12 |
|
15 | | -2. Start: |
| 13 | +[](https://codespaces.new/github/java-codespaces) |
| 14 | +[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/github/java-codespaces) |
16 | 15 |
|
17 | | - java --module-path sample-app/target/classes --module com.example.app/com.example.app.Application |
| 16 | +You can also run this repository locally by following these instructions: |
| 17 | +1. Clone the repo to your local machine `git clone https://github.com/github/java-codespaces` |
| 18 | +1. Open repo in VS Code |
18 | 19 |
|
19 | | -3. Open in browser: |
| 20 | +## Getting started |
20 | 21 |
|
21 | | - http://localhost:8080 |
22 | | - |
23 | | -## API |
24 | | - |
25 | | -- `GET /api/weatherforecast` returns a 5-day forecast JSON payload. |
| 22 | +1. **📤 One-click setup**: [Open a new Codespace](https://codespaces.new/github/java-codespaces), giving you a fully configured cloud developer environment. |
| 23 | +2. **▶️ Build and run**: |
| 24 | + - Compile: `mvn compile -f sample-app/pom.xml` |
| 25 | + - Start: `java --module-path sample-app/target/classes --module com.example.app/com.example.app.Application` |
| 26 | +3. Open the forwarded port **8080** in your browser. |
| 27 | + - Web app: `/` |
| 28 | + - API endpoint: `/api/weatherforecast` |
| 29 | +4. **🔄 Iterate quickly:** Update Java, HTML, CSS, or JavaScript files and rerun as needed while using VS Code debugging tools. |
| 30 | +5. To stop running, return to VS Code and stop the running process/task. |
26 | 31 |
|
27 | 32 | ## Project Structure |
28 | 33 |
|
29 | 34 | ``` |
30 | 35 | sample-app/ |
31 | 36 | ├── pom.xml |
32 | 37 | └── src/main/ |
33 | | - ├── java/com/example/app/ |
34 | | - │ ├── Application.java |
35 | | - │ ├── StaticFileHandler.java |
36 | | - │ ├── WeatherForecast.java |
37 | | - │ ├── WeatherForecastService.java |
38 | | - │ └── WeatherHttpServer.java |
39 | | - └── resources/static/ |
40 | | - ├── index.html |
41 | | - ├── css/site.css |
42 | | - └── js/app.js |
| 38 | + ├── java/ |
| 39 | + │ ├── module-info.java |
| 40 | + │ └── com/example/app/ |
| 41 | + │ ├── Application.java |
| 42 | + │ ├── StaticFileHandler.java |
| 43 | + │ ├── WeatherForecast.java |
| 44 | + │ ├── WeatherForecastService.java |
| 45 | + │ └── WeatherHttpServer.java |
| 46 | + └── resources/static/ |
| 47 | + ├── index.html |
| 48 | + ├── css/site.css |
| 49 | + └── js/app.js |
43 | 50 | ``` |
44 | 51 |
|
45 | 52 | ## Tech Stack |
|
0 commit comments