Tag Archives: java

Convert react app built with frontend-maven-plugin from webpack to vite

The frontend-karaf-demo project is a maven project that builds a jar file containing a servlet and compiles a react application, with frontend-maven-plugin, into static files that can be added to the jar file’s classpath and be served by the servlet.

With the frontend-maven-plugin, building a webapp can be integrated into a maven build, without the builder having to download and install node.js. The frontend-maven-plugin downloads its own node.js to handle npm depdencies and do the build.

This bloggpost describes the things I had to do, to convert the webapp build in this setup from webpack to vite.

Note: to follow this recipe npm must be installed (but it is possible to achieve the same effects by manually editing package.json). Continue reading Convert react app built with frontend-maven-plugin from webpack to vite

Build Java records with builders

When writing Java record withers what and when I discovered that the Java beans with builders resulting from Build beans better with builders could have their boiler plate code size reduced to half, if they were turned into records instead of beans.

This is the story of switching my Java beans to records and how that worked with jackson to build JSON objects from records and parse JSON objects into records. Continue reading Build Java records with builders

Java record withers what and when

This blog post is the result of searching the internet to find out what Java records with “withers” will look like and in what version of Java records with withers will arrive.

In addition, while trying to figure out Java withers, I discovered that reforming my current beans with builders into records with builders, I could throw away half the boiler plate code. Continue reading Java record withers what and when

Build beans better with builders

Edit: I no longer use beans with builders, I Build Java records with builders

Builders provide a nice, if verbose, way to create immutable java beans.

The upsides are a nice syntax for creating immutable beans, and a way to provide copy-on-write behaviour for immutable objects.

The downsides are the need for verbose boilerplate code, approximately doubling the code size of the bean source files, and the overhead of one extra object created and then left for garbage collection, for each created bean.

Continue reading Build beans better with builders

Chaining Optionals using flatMap and map

The blog post How I learnt to like Optional shows an example of how to chain Optional values safely, using Optional.orElse() to provide empty objects for the next level in the chain.

This blog post uses Optional.flatMap() and Optional.map(), to achieve the same thing, without having to create the empty objects, and without doing any evaluation for empty objects.

Continue reading Chaining Optionals using flatMap and map

How I learnt to like Optional

I used to see Optional<Something> as a completely useless addition to Java, adding to the bloat of Java without being any clearer than checking if a reference is null.

I have changed my mind, and now think Optional<> can be useful in making code simpler, easier to understand, and more robust.

The reason I changed my mind, was the usefulness of Optional.orElseThrow() when having to traverse deeply nested data structures in Java code.

Continue reading How I learnt to like Optional

Installing apache karaf on debian

Until the RFP (Request For Packaging) bug for karaf in the debian bug tracker is resolved, here is an APT archive with a karaf package for debian (architecture “all”).  The package is created using native debian packaging tools, and built from a source tarball and the APT archive itself is created, using aptly.
Continue reading Installing apache karaf on debian

Packaging karaf with native debian packaging tools

Note! This is an improvement over the packaging in  Installing apache karaf on debian stretch, this package is packaged using native debian packaging tools instead of fpm, and is built from the karaf source tarball instead of the karaf binary tarball.

Apache karaf is an OSGi container and application server that is provisioned from maven, and has an ssh server. Basically it is possible to start an empty karaf, ssh in and give some commands to install an application using maven.

There still isn’t a native .deb package on maven (see  the RFP (Request For Packaging) bug for karaf in the debian bug tracker), but this package can be installed from my own maven repository.

The packacing projecct can be found on github: https://github.com/steinarb/karaf-debian
Continue reading Packaging karaf with native debian packaging tools

Installing apache karaf on debian stretch

Edit: It is now possible to install karaf on debian without building it yourself, the package installed is not the one described here, but the new and improved package built from source with native debian packaging tools, that can be found here  https://github.com/steinarb/karaf-debian
Continue reading Installing apache karaf on debian stretch

Making a Java windows service in 10 minutes

This blog post describes how to create a windows service from a Java application, it is a slightly more fleshed out version of the JavaZone 2016 lightning talk “A Java windows service in 10 minutes”.

A problem sometimes encountered by a Java programmer, is to make your Java program into a Windows Service. This is may be a bump in your project, particularly if you don’t know anything about windows services, or much about windows for that matter.

The demo created a running, working, Windows service server using 14 lines of Java code, and some maven configuration.
Continue reading Making a Java windows service in 10 minutes