javaprocessingnoclassdeffounderrorrenderer

How to use P2D, P3D, FX2D with plain Java?


I have only worked with Processing's standard renderer until now. I got a java project where i am working with processing included via maven. Since other renderers might be faster, i wanted to try using another for my current project, but any other renderer fails for me (P2D, P3D, FX2D). Only the default, Java2D works.

Seemed weird to me, so i started another project with nothing in it, just creating an empty frame. I first tried running it in the Processing.exe as a sketch, and it worked:

The Sketch code:

void setup()
{
  size(500, 200, P3D);
}

void draw()
{
}

I then rewrote it into plain java:

import processing.core.PApplet;

public class Test extends PApplet
{

        public void setup() {
        }

        public void draw() {
        }

        public void settings() {
                this.size(500, 200, P3D);
        }

        public static void main(final String[] passedArgs) {
                final String[] appletArgs = { "Test" };
                if (passedArgs != null) {
                        PApplet.main(concat(appletArgs, passedArgs));
                }
                else {
                        PApplet.main(appletArgs);
                }
        }
}

No matter what i tried so far, i keep running into the following exeption:

java.lang.NoClassDefFoundError: com/jogamp/opengl/GLException
    at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:712)
    at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:569)
    at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:35)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at processing.core.PApplet.makeGraphics(PApplet.java:2235)
    at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2314)
    at processing.core.PApplet.initSurface(PApplet.java:10828)
    at processing.core.PApplet.runSketch(PApplet.java:10767)
    at processing.core.PApplet.main(PApplet.java:10467)
    at Test.main(Test.java:19)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 14 more
java.lang.RuntimeException: com/jogamp/opengl/GLException
    at processing.core.PApplet.makeGraphics(PApplet.java:2268)
    at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2314)
    at processing.core.PApplet.initSurface(PApplet.java:10828)
    at processing.core.PApplet.runSketch(PApplet.java:10767)
    at processing.core.PApplet.main(PApplet.java:10467)
    at Test.main(Test.java:19)

I am working with Java 17, and already tried to run with Java 8 as i read this might work, but.. it didnt. Is it not possible to run those P2D, P3D, FX2D sketches outside of the processing.exe?


Solution

  • An even better solution to this problem would be to just use the newer processing4. Micycle1 made the processing4-core usable with maven via JitPack: https://github.com/micycle1/processing-core-4