Looking for Tutorial to make library of various functions


Hi there,

I would like to learn how to make a simple java library containing various functions usable in Processing.
A simple jar file that I put in a sketchbook directory called code …
Does a tutorial exist somewhere?
Thanks for your help.
Have a good day.


I don’t know about a tutorial, but I know that you can put libraries as singular .jar files in Sketchbook\libraries\(library name)\library\(library name).jar - and on next Processing startup it will recognize it being there - then you use the “Sketch” drop-down menu in Processing, then “Libraries”, and it should be at the bottom of the list.

If I remember correctly, (library name) should be the same for folder name and .jar file name, for it to work. That might not be true though, but still is a good practice for organization.


I already use external libraries that I put in a directory of the sketchbook. It works fine.
Today, I would like to learn how to do this kind of libraries. A simple library containing functions.
Why ? to lighten the code in Processing.


If I understood you correctly, you want to make a .jar file that could be used as a library, with Processing. Is that correct?

I feel like a thing that would work fine is to take the Processing sketch you want to export into a library, then export it as executable, go into its path, then “lib” directory, and snatch the .jar file that’s named as that sketch - and use it as your library.

For understanding purposes, you can look into a .jar file as an archive and see how .class files are arranged there, figure out how these in some other library relate to the import and usage procedures you do with that library, and then use the same relation to figure out how to use your own library.


Waouh ! it’s sound great what you wrote…
A simply way to do what I want !
I try and tell you
Thank you !


No problem!
I just checked, and it seems to work completely. Had to find out how to import a library to just one sketch though, but it does work as a library now!


Did you manage to import the new library (via the jar file made under processing ) in a sketch ?
Me no…pfff


Yes. It’s a pretty simple process.
First, I made myself a new sketch, defined a function and a class in there, and saved it.

Then, I exported it as executable, navigated to the result’s folder, and then to lib folder:

Then, I made a new sketch and simply drag-n-dropped the .jar file right onto the Processing window. And it just instantly worked.

Now, it would have probably been better if I were to make f1 and banana definitions static though, so that I wouldn’t have to define a testBanana to get the function and the class off it, but, hey, it works.


So easy…
I love !
This is a real good workaround.
Thank you so much.
Hey People do you know Architector_4 ?
No ! too bad for you !



To conclude,
How to make your own library using Processing ?
1-Create a sketch (here myLib) containing your functions
In my example below 2 functions numDayOfYear() and date2sec1970()

2- Save your sketch and export it as an exe.

3- Create a sketch where you’ll use your library (here useMyLib.pde)

4-Drag and drop the jar file created after the export to useMyLib.pde window.
the jar file to drag is myLib.jar (see below):


5-To use your functions in the new sketch called useMyLib.pde see below


Cool ! no ? Tell me if not …


Glad I could help!

Yeah… With other, big IDEs and their trees of trees everywhere - even in settings, the idea of just dragging and dropping libraries right onto your code and have them magically work, it’s unusual! But awesome!

I’m in awe of the combination of simplicity and power of Processing… I think I wouldn’t have been able to jump to start making real Java code completely knowing what I’m doing without it.


Yes here we can clearly see the power of Processing.
And you were good too…
Good night !