Month: October 2023

  • Start Spring Boot with classpath and class

    There is an easy way to start a Spring Boot application by just calling

    java -jar MyApplication-0.0.1.jar

    This requires all dependencies to be bundled into the jar file and makes the jar file “fat”. That’s also the key word to search for when trying to create a complete jar.

    But there is another way.

    For example if I want to allow users to exchange the logging framework or allow the usage of different database drivers the dependencies can be exported into a separate directory using the following lines in the “build.gradle” build definition:

    task copyRuntimeLibs(type: Copy, group: 'build', description: 'Export dependencies.') {
    	into "build/deps"
    	from configurations.runtimeClasspath
    }

    Executing this task will copy all the runtime dependencies, like Spring Boot and transient libraries, into a folder called “build/deps”.

    I can then start my application from the project directory with the following command:

    java -cp "build/libs/*;build/deps/*" my.application.MainClass

    Hope this helps somebody.

  • Wait for host in BaSH

    Okay, this one is a little specific, but I recently had this issue and I wanted to share it because knowing this would have saved me one scripting language and a lot of time. I have previously implemented this in PowerShell, but it can easily be done in BaSH as well.

    The premise was to setup a new virtual machine and before I could work with the machine I had to wait until it was created and powered up. The installation was done in a pipeline and so there was no interaction. The following script waits until the machine is available and can be pinged and then terminates. This is not a finished solution but a small part of the pipeline that allowed me to continue with the regular installation via SSH after the machine was available.