How to create a Spring Boot project using IntelliJ Community Edition

Januar 26, 2023 - Lesezeit: 148 Minuten

As IntelliJ CE does not provide the Spring Bundle Plugins out of the box (Details), you can initiate the project using Spring Initializr (https://start.spring.io) for example with the following options:

  • Project: Maven
  • Language: Java
  • Spring Boot: 2.7.8
  • Group: com.yourcompany or even com.anh.hoang :)
  • Artifact: fat-jar-webserver
  • Description: Spring Boot Executable Jar Project
  • Package name: com.anh.hoang.fat-jar-server
  • Packaging: Jar
  • Java: 8 for compatibility sake
  • Dependencies:
    • Spring Web
  • Finally Generate

Back to IntelliJ

  • Extract fat-jar-server.zip
  • Open > fat-jar-server/pom.xml > Open as Project
  • Create new package config, web
  • In package config > New > Java Class > Add new class WebConfiguration
  • Content:
package com.anh.hoang.fatjarwebserver.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WebConfiguration {
@Value("${customer.name}")
private String customer;

public String getCustomer() {
return customer;
}
}
  • In package web > New > Java Class > Add new class CustomerResource
  • Content:
package com.anh.hoang.fatjarwebserver.web;

import com.anh.hoang.fatjarwebserver.config.WebConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerResource {

@Autowired
WebConfiguration webConfiguration;

@GetMapping("/customer")
public String getCustomer(){
return webConfiguration.getCustomer();
}
}
  • Remove the 2 unneeded folders for now
  • Add content to resouces/application.properties
server.port=8686
customer.name=John Wayne
  • As we have added Maven Plugin, we now can use Maven to clean, build and deploy the project:
  • Now execute mvn clean and make sure the BUILD SUCCESS with exit code 0
  • Next execute mvn install
  • In case you face the following issue:
invalid target release: 17
Module fat-jar-server SDK 1.8 is not compatible with the source version 17.
Upgrade Module SDK in project settings to 17 or higher. Open project settings.
  • Most probably the java version in your pom.xml is not right, so update it from
<properties>
<java.version>17</java.version>
</properties>

to

<properties>
<java.version>1.8</java.version>
</properties>
  • Next is when you face the issue
cannot access org.springframework.beans.factory.annotation.Value

It could be becasue of the following error:

Well if this is the case, that means that instead of Spring Boot 2, you wet for 3.0.2 instead. This requires a higher Java version (Java 17, major release 61). So it would make sense if you can jump back to step 1 and initialize the project using a compatible Spring Boot and Java set.

  • If mvn install worked as expected and the BUILD SUCCESS with exit code 0, you should be able to find a target/fat-jar-webserver-0.0.1-SNAPSHOT.jar which is our fat jar containing all the libraries needed.
  • Now you can either right click on the jar file and Run or
  • Ctrl+Shift+F10 to run it or
  • exevute the following command from the terminal:
    java -jar .\target\fat-jar-webserver-0.0.1-SNAPSHOT.jar
  • The Website will then be available under:
    http://localhost:8686/customer
  • You can create a target/config folder and paste an application.properties file inside. Change the port and the customer name as pleased and execute java -jar .\target\fat-jar-webserver-0.0.1-SNAPSHOT.jar to notice the different configuration.
  • In case you did not create the config folder for your jar file, it is still totally fine, as the jar file will turns back to the included application.properties in the package itself and use this as standard parameters to operate with.


How to set up Heimdall on RaspBerry Pi 4B using Portainer CE

Januar 15, 2023 - Lesezeit: 3 Minuten

First, we create a volume for data persistency

Then let's look for an supported heimdall image on dockerhub. You could build one yourself as well or use the one built by the linuxserver community as an alternative (https://hub.docker.com/r/linuxserver/heimdall). Whichever option you choose, the image must support arm architcture for it to work  on your Pi.

Next, let's have a look at the docker compose file and let's configure it in our Portainer Container settings.

---
version: "2.1"
services:
  heimdall:
    image: lscr.io/linuxserver/heimdall:latest
    container_name: heimdall
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
    volumes:
      - /path/to/appdata/config:/config
    ports:
      - 80:80
      - 443:443
    restart: unless-stopped

We create a container for Heimdall using the image we have chosen. As you could see, I have decided to map other ports to 80 and 443, which are needed by Heimdall. So my Heimdall will be reached via broser using 8080 and 8443 instead of 80 and 443. It's up to you which ports you have available on your environment and want to use for the mapping, just keep it as less messy as possible.

Set Interactive and TTY as well so that you can be cool and can access this Heimdall container using ssh.

Now I come back to the volume we have created above in the fist step and map it to the config folder needed to store Heimdall config in the container. With this, even the on the next start Heimdall will still remember what needs to be displayed on the dashboard and will not forget your stuff.

Remember the 3 environment variables above, which are needed? Let's create them and set them accordingly.

I preferred the always restart option over the unless stopped, so this has been set as well.

That's it, now Deploy the container and you're good to go.

Afterwards, your Heimdall will be reachable via browser using:

https://<ip-or-hostname>:9443
https://raspberrypi:9443


Simple Bar Chart in Excel

Januar 15, 2023 - Lesezeit: ~1 Minute
Data Output Excel EN Code Excel DE Code
15 ||||||||||||||| =REPT("|";A1) =WIEDERHOLEN("|";A1)
22 |||||||||||||||||||||| =REPT("|";A2) =WIEDERHOLEN("|";A2)
7 ||||||| =REPT("|";A3) =WIEDERHOLEN("|";A3)


How to set up Raspberry Pi 4B with Docker and Portainer CE

Januar 15, 2023 - Lesezeit: 5 Minuten

Raspberry Pi

In case you did not buy the bundle with the pre-formatted SD Card, start with formatting your SD Card to FAT 32.

You can do so using various tools. In case you are looking for some options, Rufus or AOMEI Partition Assistant might be worth your consideration.

Next download the Imager from https://www.raspberrypi.com/software

Since we are not looking for desktop but rather a server running 24/7, let's choose the lite version of the OS:

Raspberry Pi OS (other) > Raspberry Pi OS Lite (32-bit)

Click Shift Ctrl + X or Enter Settings to enable SSH directly. Also set the hostname so that you do not have to fiddle with your router for the IP address of your Raspberry Pi afterwards. Telemetry is not needed for our purpose so you can deactivate it. Lastly it is recommended to use your own user instead of the standard user "pi" and set an appropiate password for it.

You can also generate an empty file named "ssh" in the "boot" folder on your SD card to enable the SSH access in case is was forgotten before.

Now Remove the SD Card from your PC, plug it into your Pi, plug in the LAN cable and plug in the power cable. Your Pi will boot automatically. Find the IP for your Pi on the Router in use, or connect to your Pi using the hostname.

ssh:<user>@<ip-or-hostname>
ssh:pi@raspberrypi

Well then, let's update the OS to the latest greatest first before we continue messing around with it:

sudo apt update && sudo apt upgrade
sudo reboot
Docker Installation

Meanwhile, you can read about the Docker Installation here: https://docs.docker.com/engine/install/debian/

If you came to this page after a broken docker installation, remove it first before continue. Like so:

sudo apt-get remove docker docker-engine docker.io containerd runc

Now let's install using the convenience script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh

If you want to test the installation first, then use the command with DRYRUN option instead

DRY_RUN=1 sudo sh ./get-docker.sh
Add your user to the docker group, then either reboot or reload the new group change:
sudo usermod -aG docker $USER
#sudo usermod -aG docker <my-user>
#sudo reboot
newgrp docker

Now verify the docker version, run a test container and show running containers:

docker –version
docker run hello-world
docker ps
Portainer Community Edition Installation

Details can be read here, remember to choose community edition: https://docs.portainer.io/start/install/server/docker/linux

First let's create a volume for data persistency:

docker volume create portainer_data

The following command will do the job for you, basically download and install the Portainer Server container: 

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
There you go, now Portainer should be easily found as running using docker ps and via browser:
https://rspberrypi:9443
https://<ip-or-hostname>:9443
Remember that localhost:9443 only works if you are on the RaspberryPi itself.

Update Hostname for Raspberry Pi 4B

Januar 15, 2023 - Lesezeit: ~1 Minute

Raspberry Pi

sudo raspi-config
# Select System Options or Network Options
# Select Hostname
# Enter a new hostname
# Finish & Yes to Reboot