|
| 1 | +--- |
| 2 | +layout: tutorial |
| 3 | +official: true |
| 4 | +title: "Setting up Javalin with Bazel & Kotlin using a template" |
| 5 | +author: <a href="https://www.linkedin.com/in/fagerjord/" target="_blank">Jørund B. Fagerjord</a> |
| 6 | +github: https://github.com/javalin/kotlin-javalin-bazel-starter |
| 7 | +date: 2022-11-30 |
| 8 | +permalink: /tutorials/bazel |
| 9 | +summarytitle: Bazel setup |
| 10 | +summary: Run your Javalin app with Bazel, from a template project |
| 11 | +language: kotlin |
| 12 | +--- |
| 13 | + |
| 14 | +## About Bazel |
| 15 | + |
| 16 | +[Bazel](https://bazel.build/) is a build tool that was created by Google. It's fast and correct, and it supports multiple languages. See [Why Bazel](https://bazel.build/about/why). |
| 17 | + |
| 18 | +## What do you need? |
| 19 | + |
| 20 | +- [Bazelisk](https://github.com/bazelbuild/bazelisk): A user-friendly launcher for Bazel. It will download the correct version of Bazel for you. |
| 21 | + - macOS: `brew install bazelisk` |
| 22 | + - Windows: `choco install bazelisk` |
| 23 | +- [git](https://git-scm.com/): To clone the project |
| 24 | + - macOS: `brew install git` |
| 25 | + - Windows: `choco install git` |
| 26 | +- <https://github.com/jorunfa/kotlin-javalin-bazel-starter> |
| 27 | + - In this tutorial we'll use *kotlin-javalin-bazel-starter* project on GitHub. Follow the steps below to get started. |
| 28 | + |
| 29 | +## Steps |
| 30 | + |
| 31 | +### 1. Use the template project |
| 32 | + |
| 33 | +```bash |
| 34 | +git clone [email protected]:javalin/kotlin-javalin-bazel-starter my-javalin-app |
| 35 | +cd my-javalin-app |
| 36 | +``` |
| 37 | + |
| 38 | +### 2. Run the application |
| 39 | + |
| 40 | +```bash |
| 41 | +bazel run //:server |
| 42 | +``` |
| 43 | + |
| 44 | +Should output something like: |
| 45 | + |
| 46 | +```text |
| 47 | +Starting local Bazel server and connecting to it... |
| 48 | +INFO: Invocation ID: 84c2e9f4-6392-427c-ad4b-22f4fcd3010a |
| 49 | +INFO: Analyzed target //:server (61 packages loaded, 1022 targets configured). |
| 50 | +INFO: Found 1 target... |
| 51 | +Target //:server up-to-date: |
| 52 | + bazel-bin/server.jar |
| 53 | + bazel-bin/server |
| 54 | +INFO: Elapsed time: 5.741s, Critical Path: 4.47s |
| 55 | +INFO: 85 processes: 10 internal, 69 darwin-sandbox, 6 worker. |
| 56 | +INFO: Build completed successfully, 85 total actions |
| 57 | +INFO: Running command line: bazel-bin/server |
| 58 | +[main] INFO io.javalin.Javalin - Starting Javalin ... |
| 59 | +[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.15; built: 2023-04-11T18:37:53.775Z; git: 5bc5e562c8d05c5862505aebe5cf83a61bdbcb96; jvm 20+36 |
| 60 | +[main] INFO org.eclipse.jetty.server.session.DefaultSessionIdManager - Session workerName=node0 |
| 61 | +[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started i.j.j.@304bb45b{/,null,AVAILABLE} |
| 62 | +[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@7dc0f706{HTTP/1.1, (http/1.1)}{0.0.0.0:7070} |
| 63 | +[main] INFO org.eclipse.jetty.server.Server - Started Server@2f465398{STARTING}[11.0.15,sto=0] @267ms |
| 64 | +[main] INFO io.javalin.Javalin - |
| 65 | + __ ___ ______ |
| 66 | + / /___ __ ______ _/ (_)___ / ____/ |
| 67 | + __ / / __ `/ | / / __ `/ / / __ \ /___ \ |
| 68 | +/ /_/ / /_/ /| |/ / /_/ / / / / / / ____/ / |
| 69 | +\____/\__,_/ |___/\__,_/_/_/_/ /_/ /_____/ |
| 70 | +
|
| 71 | + https://javalin.io/documentation |
| 72 | +
|
| 73 | +[main] INFO io.javalin.Javalin - Listening on http://localhost:7070/ |
| 74 | +[main] INFO io.javalin.Javalin - You are running Javalin 5.6.1 (released June 22, 2023. Your Javalin version is 143 days old. Consider checking for a newer version.). |
| 75 | +[main] INFO io.javalin.Javalin - Javalin started in 180ms \o/ |
| 76 | +``` |
| 77 | + |
| 78 | +### 3. Open the application in your browser |
| 79 | + |
| 80 | +In a new terminal window, run: |
| 81 | + |
| 82 | +```bash |
| 83 | +open http://localhost:7070 |
| 84 | +``` |
| 85 | + |
| 86 | +Or just open <http://localhost:7070> in your browser. |
| 87 | + |
| 88 | +Which should produce the following output: |
| 89 | + |
| 90 | +```html |
| 91 | +Hello World |
| 92 | +``` |
| 93 | + |
| 94 | +## Conclusion |
| 95 | + |
| 96 | +In this tutorial, we have: |
| 97 | + |
| 98 | +1. Used a template project to get started with Javalin, Kotlin and Bazel |
| 99 | +2. Run the application with Bazel |
| 100 | +3. Opened the application in our browser |
0 commit comments