1

I’m building a web application in Java, with Spring Boot, and would like to include Processing as a library. Processing = the language focussed on visuals (which you can use as a library in Java). I’m using Intellij IDEA, the project is set-up as a Maven project and I believe the pom.xml includes all the necessary dependencies.

I’m stuck with running a sketch of the Processing library in the Spring Boot application. What I want to achieve is a Processing sketch is triggered when a certain event happens on the client side; the Spring Boot application is already running when this event occurs. For running my application I run the SpringBootApplication. This works fine.

package io.eho.foo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FooApplication {
    public static void main(String[] args)
    {
        SpringApplication.run(FooApplication.class, args);
    }
}

I do manage to run a Processing sketch on its own, with its own main method, without running my Spring Boot application.

package io.eho.foo.play.sketchtest;

import processing.core.PApplet;

public class PlaySketch extends PApplet {

    @Override
    public void setup() {
        background(111, 222, 11);
    }

    @Override
    public void settings() {
        size(400, 400);
    }

    public static void main(String[] args) {
        String[] processingArgs = {"PlaySketch"};
        PlaySketch playSketch = new PlaySketch();
        PApplet.runSketch(processingArgs, playSketch);
    }
}

This launches a PApplet (just a frame with green background).

I do NOT succeed launching the PApplet when running the Spring Boot application. I do not get how to trigger the additional main method for the PApplet when the Spring Boot application is either:

  • already running
  • or triggered to run.

I tried to trigger the main method of the processing sketch class via calling its main in the main method of the SpringBootApplication:

package io.eho.foo;

import io.eho.foo.play.sketchtest.PlaySketch;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FooApplication {

    public static void main(String[] args)
    {
        SpringApplication.run(FooApplication.class, args);

        PlaySketch.main(args);
    }
}

combined with the same code for PlaySketch as above.

I tried to include the args to run the processing sketch in the main method of the Spring Boot application:

package io.eho.foo;

import io.eho.foo.play.sketchtest.PlaySketch;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import processing.core.PApplet;

@SpringBootApplication
public class FooApplication {

    public static void main(String[] args)
    {
        SpringApplication.run(FooApplication.class, args);

        String[] processingArgs = {"PlaySketch"};
        PlaySketch playSketch = new PlaySketch();
        PApplet.runSketch(processingArgs, playSketch);
    }
}

Combined with:

  • the same PlaySketch code as above
  • no main for PlaySketch
  • empty main for PlaySketch

All these trials produce this message (or error, it is not clear to me if it is an error or a information):

… Cannot run sketch without a display. Read this for possible solutions: https://github.com/processing/processing/wiki/Running-without-a-Display

The Github link referred to explains how to set-up running Processing without a display - which is not what i want / intended at all.

I realize I do not fully understand what I’m doing with the 2 main methods. But a day of trials and googling around to find answers didn’t result in a solution.. Anyone has an idea what I am doing wrong?

This is my first question here - I hope it is clear, but if not, let me know what i can add to clarify. I also hope I’m just missing something pretty straightforward :)

Thanks, Erik

erikh
  • 11
  • 1
  • 2
  • I found a solution to my issue: just before I create a PApplet, I set: `System.setProperty("java.awt.headless", "false");` I guess a SpringBoot app does need to have this property explicitly set to false to make it a 'headfull' app. Happy to continue finding next issues :) – erikh Sep 10 '22 at 13:15

0 Answers0