Logo

dev-resources.site

for different kinds of informations.

[HttpServer series] Setting up the dev environment

Published at
1/2/2024
Categories
java
frameworks
learning
Author
mandraketech
Categories
3 categories in total
java
open
frameworks
open
learning
open
Author
12 person written this
mandraketech
open
[HttpServer series] Setting up the dev environment

Now that there is enough context on the objectives of this series, let's get started with setting up our dev environment.

My preference is to use Docker, and Visual Studio Code (VSCode). With this combination, I can set up a devcontainer ( https://containers.dev ) and hence have nothing to install on my machine. This allows me to control the tools that will be available to my application, on the same machine, in production. And also, set up a database, and reverse proxy along with.

Recently I figured that there is a way to set up a reverse ssh-tunnel too, with the help of Cloudflare ( https://www.cloudflare.com/en-in/products/tunnel/ ). There are various other offerings, but I am going with the recommendation of the maintainer of Awesome Tunneling.

Based on the above two approaches, and a custom Docker image for JDK (improvised from my work published in Installing JDK in Docker ), I have created a new git repo ( https://gitlab.com/mandraketech/java-vscode-dev ). This is a simple dev environment that will create a Java dev environment. It has a JDK installed ( Liberica or Eclipse Temurin, based on the env file ), Maven and a script, in the tools directory, that will fetch the latest versions for both those tools, so you can update, on need. There is, in the README.md, instructions to create an Empty Java maven project using the maven-archetype-quickstart , in case you are looking for a fresh start. The .devcontainer.json contains instructions on running one of the three available environments:

  • With Cloudflare Tunnel ( uses a ssh tunnel, and certificates for https support )

  • With Caddy as the reverse-proxy / loadbalancer ( supports https )

  • Port directly exposed via devcontainer tunneling

So, let me get started with creating a new environment. I have git, Docker and VS Code installed. Since all the development will happen within the DevContainer, the OS in use, for the dev environment, will only matter in the first few steps.

First step, is to fork the above dev environment, and create a project on Gitlab. When forking, I am only going to fork the main branch, because my project does not need the dev environment's local branches.

I am going to call it "HttpServer based Todo App", and set up the security policies. It is going to be a public repo, so you are welcome to use/fork/contribute merge requests.

git clone [email protected]:mandraketech/httpserver-based-todo-app.git
Enter fullscreen mode Exit fullscreen mode

Start VS Code with the source directory selected, in the above case http-server-based-todo-app.

If you want to pull the dev environment from the "upstream" repo, when it is updated, the instructions are in the tools/README.md

And then I am going to create a .env file ( using the .env.template ) to set up the external name using which we will connect to the server. I am going to use localhost:8080 , for now, since I am working with the default container environment that forwards the port from VSCode.

Now, "Reopen in Container" and we have a dev environment with Java installed. Open a terminal inside the container.

First thing is to generate an empty java project, and make sure we have everything in place to proceed with development.

cd ~/code mvn archetype:generate -DgroupId=com.example -DartifactId=sample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=falsemv sample/* .rmdir samplemvn wrapper:wrapper -Dtype=only-script
Enter fullscreen mode Exit fullscreen mode

After this, there is a new java project, with a pom file, and the maven-wrapper.

Let's enable Java 21. In pom.xml add the lines

<properties> <maven.compiler.release>21</maven.compiler.release></properties>
Enter fullscreen mode Exit fullscreen mode

Test the setup:

./mvnw clean compilejava -cp ./target/classes com.example.App./mvnw test
Enter fullscreen mode Exit fullscreen mode

You should see the Hello World output. And the test results.

Add the mandatory .gitignore to make sure we do not commut unnecessary files:

# if you are on mac.DS_Store# .env is a "private" file. Do not commit.env# java build directorytarget
Enter fullscreen mode Exit fullscreen mode

Commit this code, to the repo. Now we are ready to get to the Http Server piece in the next article.

frameworks Article's
30 articles in total
Favicon
JavaScript Frameworks - Heading into 2025
Favicon
Unlocking the Power of Django: Build Secure and Scalable Web Apps Fast
Favicon
The Best Web Development Frameworks in 2024
Favicon
Why Django Stands Out Among Web Development Frameworks
Favicon
Top JavaScript Frameworks to Master in 2024
Favicon
Fixing CORS in your SPA
Favicon
Demasiados frameworks de JS, pero por qué?
Favicon
Who's Your .NET Ally? - F# vs C#
Favicon
Angular vs React: A Frontend Showdown
Favicon
How To Install TestNG in Eclipse: Step By Step Guide
Favicon
Integrating Laravel with Popular Frontend Frameworks: A Developer's Guide
Favicon
This Month in Solid #4: The Shape of Frameworks to Come 😎
Favicon
So many JS frameworks, but why?
Favicon
Why Core Knowledge in HTML, CSS, JavaScript, and PHP is Timeless
Favicon
Frontend Frameworks from 2023-2024
Favicon
Java GUI Frameworks: Some go for these fine tools
Favicon
Spring Boot vs Quarkus: Pick one for Java
Favicon
[HttpServer Series] Authentication and Role based Authorization (RBAC)
Favicon
Stuck in the Middle with You: An intro to Middleware
Favicon
Sempre vale apena usar Frameworks?
Favicon
Navigating the Frontiers of Web Development:A Deep Dive into Framework Wars
Favicon
Best Frameworks For Cross-Platform App Development
Favicon
[HttpServer series] Static File server, and Logging
Favicon
[HttpServer Series] The Http Router - from scratch - in Java
Favicon
Webinar De COBIT Para Governança de TI Gratuito da KA Solution
Favicon
[HttpServer series] Testing the server
Favicon
[HttpServer series] Getting Started - First context (endpoint)
Favicon
JavaScript Frameworks - Heading into 2024
Favicon
[HttpServer series] Setting up the dev environment
Favicon
[HttpServer series] Will it support the Performance, and Scale ?

Featured ones: