October 4, 2015

Spring Boot Tomcat logging configuration

I had a hard time in getting a SpringBoot Tomcat application configured in such a way that configuration files are read from TOMCAT_BASE/conf and log files are written to TOMCAT_BASE/logs. It should work from Eclipse as well as for an external Tomcat. Many questions and answers could be found about similiar problems, but this is what finally worked for me:

Put a bootstrap logback.xml into the classpath root and let point to the actual logging configuration:

            <include file="${catalina.base}/conf/myApp-logback.xml" />        


The logging configuration in ${catalina.base}/conf/myApp-logback.xml that writes to ${catalina.base}/logs/myApp.log looks something like this:      

            <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                                   <pattern>%d{HH:mm:ss} [%thread] %-5level - %msg%n</pattern>

            <appender name="FILE" class="ch.qos.logback.core.FileAppender">
                                   <pattern>%d{yyyy.MM.dd HH:mm:ss} [%thread] %-5level - %msg%n</pattern>

            <root level="WARN">
                        <appender-ref ref="FILE" />
                        <appender-ref ref="STDOUT" />

            <logger name="de.myPackage" level="DEBUG"/>            

Other application settings are in a file at ${catalina.base}/conf/myApp.properties and configured like this:

@PropertySources(value = {@PropertySource("file:${catalina.base}/conf/myApp.properties")})
public class Application extends SpringBootServletInitializer {           

            public static void main(String[] args) {

                        SpringApplication.run(Application.class, args);


Finally, when running from Eclipse, catalina.base is defined as VM argument:

Sorted Batch Rendering for LibGdx

This is a spin-off from the development of the game Biodrone Battle.
In the beginning, rendering was split up into multiple classes and as the code base grew, it was tedious to keep the right order for rendering layers of tiles and sprite components.

Furthermore, a lot of texture switches occurred. Whether that was a performance hit, was not analysed, but it was fixed easily after introducing sorted batch rendering. Taking the blend mode as sort criterium reduces the number of SpriteBatch flushes as well.

It is no longer necessary to provide an open SpriteBatch to each render class.

There are default implementations for rendering textures, particles and vertices. In case they don't meet your needs, just derive your own item classes from BatchRenderItem. The first sort criterium is always the layer (z-index) followed by individual criteria like texture handle or blend mode.

Run BatchQueueLauncher to get a first impression.

Create a render queue for texture items:
        renderQueue = new BatchRenderQueue(MAX_LAYERS);
        renderQueue.addItemClass(TextureBatchItem.class, new Pool() {
            protected TextureBatchItem newObject() {
                return new TextureBatchItem();
Queue a batch item:
            TextureBatchItem batchItem = renderQueue.obtainItem(TextureBatchItem.class);
            batchItem.setLocation(123, 456);

Draw all queued items:
private void render(BatchRenderQueue renderQueue, SpriteBatch batch) {
        long time = System.nanoTime();
        renderQueue.render(batch, time);

Blackcat - a lightweight dependency injection library for Java

Blackcat was developed while working on the game Biodrone Battle.
Requirements were as follows:
  • no external dependencies
  • no component scanning
  • no code generation, no byte code modification, no configuration files
  • no black magic, simple to use and fast
It can do two things:
  • annotation based field injections
  • invoke post construction callbacks
To get the gist of this library, check out the unit tests.

Simple example for building a band consisting of guitar and bass:
public class Band {
    private Guitar guitar;

    private Bass bass;

    public Band() {

public class Guitar {
    public Guitar() {

public class Bass {
    public Bass() {
Injector injector = Injector.getInjector();

// declare DI components
injector.addComponent(Band.class, Band::new);
injector.addComponent(Guitar.class, Guitar::new);
injector.addComponent(Bass.class, Guitar::new);

// get the band together
Band band = injector.getComponent(Band.class);