Processing is a combination of libraries and tools. This page demonstrates how to use Processing in Eclipse, without using the Processing IDE.

The Processing IDE, guides on using Processing, and other resources can be found at: https://processing.org/.

Environment

Setting up Eclipse shows how to download and configure JDK 17 and Eclipse.

Option 1: Import complete Eclipse project

The project below can be imported into Eclipse. It contains core.jar on the build path and HelloWorld.java.

The project assumes that Eclipse is set to use Java 17 as the default for both the JRE and the compiler compliance level.

HelloWorld.zip

  1. Open the Eclipse Import dialog. If the Package Explorer does not have any projects, select Import Projects. If the Package Explorer has at least 1 project, right click on any white space and choose Import.
  2. Choose General -> Existing Projects into Workspace. Eclipse Import dialog
  3. Choose Select archive file. Browse to and select HelloWorld.zip. Eclipse Import Projects dialog

Option 2: Add Processing library to existing project

core.jar

The main Processing library is stored in core.jar. The core.jar file below was extracted from Processing 4.2 for macOS 64 bit Intel. It appears to have the same contents as the versions for Apple Silicon and for Windows 64 bit. An Eclipse project using this core.jar file was tested on all 3 system types (a Mac with an Intel chip, a Mac with an Apple chip, and a Windows machine).

core.jar

Get core.jar from processing.org

To get core.jar directly from processing.org, download the lastest version of Processing.

For the Windows version, extract the zip file. The path is core -> library -> core.jar.

For both macOS versions, extract the zip file then right click on the app and choose “Show Package Contents”. The path is Contents -> Java -> core -> library -> core.jar.

Add core.jar to Eclipse project build path

  1. Right click on the Eclipse project. Choose New -> Folder. Making new folder
  2. Name the folder libs (for libraries). Naming new folder
  3. Drag core.jar from File Explorer / Finder into the new folder. Choose Copy files. File copy
  4. Right click on core.jar. Choose Build Path -> Add to Build Path. Adding to build path

HelloWorld class using Processing in Eclipse

package helloWorld;

import processing.core.PApplet;

public class HelloWorld extends PApplet
{
    public static void main(String[] args)
    {
        PApplet.main("helloWorld.HelloWorld");
    }
    
    public void settings()
    {
        size(100, 100);
    }
    
    public void setup()
    {
        
    }
    
    public void draw()
    {
        background(0);
        text("Hello world", 10, 50);
    }
}

HelloWorld.java

The program displays a black box with white text.

Extending PApplet

The methods and fields built into Processing are accessed by making the class with the main method extend the PApplet class. The PApplet class must be imported.

Failing to extend PApplet results in compile time errors when calling Processing methods. For example: The method size(int, int) is undefined for the type HelloWorld.

Failing to import PApplet results in the compile time error PApplet cannot be resolved to a type.

main method

When using Processing in Eclipse, the main method contains a single call to PApplet.main. The argument is the fully qualified class name (including any package).

This HelloWorld class is in the helloWorld package, so the fully qualified class name is "helloWorld.HelloWorld".

The fully qualified class name is case sensitive (including both the package and class names). Misspelling the fully qualified class name results in a ClassNotFoundException. Accidentally using the fully qualified name of a different accessible Processing sketch in Eclipse results in that sketch running instead of the intended sketch (with no errors or warnings).

settings, setup, and draw methods

The settings, setup, and draw methods each override a method inherited from PApplet.

The settings method is used to set the screen size with a call to the Processing size method.

In Eclipse, the size method should only be called in settings. Calling the size method in setup or draw usually results in the compile time error: java.lang.IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html

The setup method is similar to a constructor. It is used to set the initial state. The initial state can include instance variables in the class itself as well as those in PApplet (ex: calling rectMode).

The draw method runs in a loop, just like in the Processing IDE.

Misspelling settings, setup, draw, or other built in Processing methods can result in a variety of errors. Many of these errors do not direclty hint at the root cause. Eclipse displays a green triangle in the margin for each method that overrides a superclass method. If this triangle does not appear when overriding a built in Processing method, the method might be misspelled. Standard Java @Override annotation can be used to turn misspellings into compile time errors.

Comments

Comment on Setting up Processing in Eclipse