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.

1 Like

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.

2 Likes

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 !

1 Like

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):

image

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

image

Cool ! no ? Tell me if not …

3 Likes

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 !

very nice~!

Does it work if you do it your way?

Did it work well?

If you are still interested I can be of help.

1 Like

@paulgoux, @fabwoj, @GoToLoop

Help me~ ^^.

  1. I have created a jar file.

  2. Created a library folder format.

  1. I put it in the processing folder.

  2. Restart the processing tool.

  3. Enter the code as follows.

import GOLDSTAR_LIBRARY1.* ;
GOLDSTAR_LIBRARY1 gs = new GOLDSTAR_LIBRARY1();
void setup(){
 size(1000,1000); 
 println(gs.CALCU_VALUE());    
}
  1. However, it says that the library cannot be found.
No library found for GOLDSTAR_LIBRARY1
Libraries must be installed in a folder named 'libraries' inside the sketchbook folder (see the Preferences window).
The package “GOLDSTAR_LIBRARY1” does not exist. You might be missing a library.
  1. What is the solution?

I normally just use the processing library template and the process highlighted by Dan Shiffman in his videos on the topic but if you have a .java file I can produce the lib file for you.

1 Like

Did you see the docs?

see Home · processing/processing Wiki · GitHub (Contribute)

see Library Overview · processing/processing Wiki · GitHub

and 2 other links (find them on the page from the first link)

Chrisir

1 Like

@paulgoux

Putting ‘.java’ in the folder does not work.

I don’t know why.

Java or .jar file……?