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 🎉