Skip to content

Instantly share code, notes, and snippets.

@markusand
Created May 21, 2020 10:23
Show Gist options
  • Save markusand/258290aae4027d23e25d809398aa90d3 to your computer and use it in GitHub Desktop.
Save markusand/258290aae4027d23e25d809398aa90d3 to your computer and use it in GitHub Desktop.
Create a Processing library

Create a Processing library

Compile a Processing sketch into a library that can be used with an import. This is helpful to reduce the amount of Processing tabs in a project, specially for that bunch of classes that won't be changed and belong to a same conceptual group.

Translate Processing's .pde files to .java files, getting rid of all the Processing core functions by java equivalents (ex. sin() to Math.sin()) and/or import Processing classes (ex. PVector). Add package name at the beginning of every java class file.

Open Terminal and go to sketch's directory. Type the following command

javac -cp [processing_path]:[extra_libraries] -source 1.6 -target 1.6 -d . *.java

Processing core path should be something similar to /Applications/Processing.app/Contents/Java/core/library/core.jar in macOS. Add extra library paths (if any) after Processing's core, separated with :. Be aware to fix all compilation errors that may appear.

Create .jar file running

jar cvf [library_name].jar [input_directory]

Move the jar file inside a library directory in the Processing's libraries directory.

Import the brand new library to your sketch 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment