Skip to content

Library Overview

Ben Fry edited this page Jan 19, 2023 · 2 revisions

A Processing library can be any Java code that's been given a package name and packed into a JAR file. It can also register itself with a sketch to get notification of when events happen, for instance whenever draw() is called or a key is pressed.

Contributed libraries are one of the most important aspects of the Processing project and have an enormous impact on how the community uses the software. Libraries have been designed into the larger Processing plan to enable simple extensions of the core API in new, innovative, and unexpected directions. Libraries are the future of the project as we keep the processing.core package as minimal as possible.

Another Alternative: Using the code Folder

If all you want to do is add some Java code to a sketch (for instance, a .jar file found elsewhere), sometimes you don't even need to build a full library. If you add a .jar file to your sketch (using Sketch → Add File), the file will be copied to a folder named code inside your sketch folder. When running the sketch, all packages found in the .jar file will automatically be added as import statements in the sketch (though invisible to the user).

Use a Java IDE to Create Libraries

It is not possible to build libraries from within the Processing application. In fact, creating a library with the PDE will cause problems because the JAR file exported from the PDE will contain the current version of the processing.core classes, which will cause major conflicts when trying to use any other code. Libraries that contain classes from the processing package in this manner will have to be rejected or removed from the site.

The Processing Development Environment (PDE) is built with the sole purpose of creating sketches that are part of PApplet that have a few files at most. We don't plan to extend the PDE to also support developing libraries or tools, because then it becomes like any other IDE that is quickly too general for our target audience. Users who are advanced enough in their programming skills to build libraries will almost always be skilled enough to use another IDE like Eclipse to build their library. (And if not, it's a lovely time to learn.)

Where To Put Libraries

Core libraries live inside the libraries folder of the Processing distribution. This folder is not visible on macOS (unless you right-click Processing.app and select "Show Package Contents"). All contributed libraries should be installed in the sketchbook folder inside a folder named libraries.

Build Your Own Library

If you are building your own library, the Library Template will help you to get started developing your library with the Eclipse IDE. The Library Basics section will give you a better understanding of how a library works. If you want to share your library with the Processing community, please take a look at the Library Guidelines.

Core vs. Contributed Libraries

There are two categories of libraries. Most core libraries (PDF, Serial, Net) are part of the Processing distribution, and contributed libraries are developed, owned, and maintained by members of the Processing community.

Some libraries that were part of Processing in the past (such as Video and JavaFX) have been moved to their own project, because they are very large. This also helps them be developed and updated independently from the rest of the software. You can install them using the Contributions Manager.

Occasionally, a contributed library might make its way into the regular distribution. This happened with the Candy library by mflux which eventually became the basis of the SVG parsing used by the loadShape() method, the GSVideo library from Andrés Colubri that replaced the original video library.