Skip to content

thomasbruninx/java-project-template

Repository files navigation

Java project template

A batteries-included, fully containerized Java (Gradle) project template. (With IntelliJ support)

Getting started

Prerequisites

Project structure

By default, the template has the following structure:

java-project/                       # Project root
|-- config/                         # Configuration files
|-- docs/                           # Project documentation
|-- gradle/                         # Gradle wrapper and properties
|-- src/                            # Actual Java source code
|-- build.gradle                    # Gradle build configuration
|-- settings.gradle                 # Gradle settings file
|-- gradlew                         # Gradle wrapper script (Unix)
|-- gradlew.bat                     # Gradle wrapper script (Windows)
|-- .env.example                    # Example .env file (template for .development.env and .production.env)
|-- .init.env.example               # Example .init.env file, used for initializing a new MariaDB instance
|-- Dockerfile                      # Dockerfile describing the project assembly 
|-- docker-compose.development.yml  # Docker Compose file describing the hosting stack used for development
|-- docker-compose.production.yml   # Docker Compose file describing the hosting stack used for production

Configuration

Environment variables through .env files

Dynamic configuration (like domain name, database settings, ...) gets done with .env files. Both compose files (production and development) source their own .env file (.production.env and .development.env respectively). An example .env is provided in this repository.

For the initialization of a MariaDB database, the .init.env file can be used to set an additional user, create an empty database and changing the root user's password. An example of this file is also provided in this repository.

Usage

Development

  1. Create a .development.env file to configure your project instance

  2. (Optional) Create an .init.env to initialize the MariaDB instance

  3. Launch hosting stack:

    docker compose --env-file .development.env -f docker-compose.development.yml up -d
    

All source code and configuration files are accessible for the container through "bind" mounts. You can edit them on the fly, without the need to restart the Docker container.

Production

  1. Create a .production.env file to configure your project instance

  2. (Optional) Create an .init.env to initialize the MariaDB instance

  3. Create a docker-compose.hosting.yml with the necessary networking and proxy configuration. You can see an example in the docker-compose.hosting.yml.example file.

  4. Launch hosting stack:

    docker compose --env-file .production.env -f docker-compose.production.yml -f docker-compose.hosting.yml up -d
    

The source code, dependencies and configuration files are baked into the Docker image. The SQL database storage is mounted as Docker volumes.

About

A batteries-included, fully containerized Java (Gradle) project template. (With IntelliJ support)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published