# Looking for Tutorial to make library of various functions

**URL:** <https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380>\
**Category:** Project Guidance\
**Created:** [January 10, 2019, 9:36am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380 "2019-01-10T09:36:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 9:36am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/1 "2019-01-10T09:36:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 10, 2019, 9:47am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/2 "2019-01-10T09:47:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 9:57am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/3 "2019-01-10T09:57:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 10, 2019, 10:08am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/4 "2019-01-10T10:08:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 10:14am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/5 "2019-01-10T10:14:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 10, 2019, 10:16am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/6 "2019-01-10T10:16:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 12:02pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/7 "2019-01-10T12:02:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 10, 2019, 1:38pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/8 "2019-01-10T13:38:07Z")

</div>

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.  
 ![](https://yyz2.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/ddbc2a72afa0cc90f6ee9a6d3a2813db0194631a.png)

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

 ![](https://yyz2.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/556ad88ce3ff958feb3c5363871bd38d7edd9fac.png)

Then, I made a new sketch and simply drag-n-dropped the `.jar` file right onto the Processing window. And it just instantly worked.  
 ![](https://yyz2.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/340907436f610fc71742f2ece1ca5a2e2930898b.png)

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.

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 2:27pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/9 "2019-01-10T14:27:11Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 10, 2019, 3:29pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/10 "2019-01-10T15:29:15Z")

</div>

> **[GoToLoop/Processing\_Jar\_Creation](https://github.com/GoToLoop/Processing_Jar_Creation)**
>
> Example for compiling a ".java" file and package it as a ".jar" for Processing. - GoToLoop/Processing\_Jar\_Creation

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 3:31pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/11 "2019-01-10T15:31:24Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b9b62f3ee7c39775eb8081538f99961597dce1f1.png)

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/efefee5deda0b4b489fd696eb31a16bcd3a50857.png)

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

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/01cd74637f375a8e96fcb124df8fd408601f085a.png)

Cool ! no ? Tell me if not …

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 10, 2019, 9:51pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/12 "2019-01-10T21:51:02Z")

</div>

Glad I could help!

> [@fabwoj](#):
>
> Cool ! no ? Tell me if not …

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.

---

<div class="post-metadata">

**Author:** ![fabwoj](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fabwoj/32/2364_2.png) [@fabwoj](https://discourse.processing.org/u/fabwoj)\
**Post date:** [January 10, 2019, 10:21pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/13 "2019-01-10T22:21:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [August 24, 2021, 9:02am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/14 "2021-08-24T09:02:52Z")

</div>

very nice~!

Does it work if you do it your way?

Did it work well?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 24, 2021, 9:56am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/15 "2021-08-24T09:56:36Z")

</div>

If you are still interested I can be of help.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [August 24, 2021, 10:16am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/16 "2021-08-24T10:16:58Z")

</div>

@paulgoux, @fabwoj, @GoToLoop

Help me~ ^^.

1. I have created a jar file.

2. Created a library folder format.

> **[GOLDSTAR\_LIBRARY1.zip](https://drive.google.com/file/d/1sYgRHnENIE873RnXBoc_ApUncIzhlbYB/view?usp=sharing)**
>
> Google Drive file.

1. I put it in the processing folder.

2. Restart the processing tool.

3. Enter the code as follows.

```auto
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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 24, 2021, 3:39pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/17 "2021-08-24T15:39:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 24, 2021, 4:18pm UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/18 "2021-08-24T16:18:29Z")

</div>

Did you see the docs?

see [Home · processing/processing Wiki · GitHub](https://github.com/processing/processing/wiki) (Contribute)

see [Library Overview · processing/processing Wiki · GitHub](https://github.com/processing/processing/wiki/Library-Overview)

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

Chrisir

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [August 25, 2021, 5:43am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/19 "2021-08-25T05:43:18Z")

</div>

@paulgoux

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

I don’t know why.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 25, 2021, 8:53am UTC](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380/20 "2021-08-25T08:53:44Z")

</div>

Java or .jar file……?

[Next page](https://discourse.processing.org/t/looking-for-tutorial-to-make-library-of-various-functions/7380.md?page=2)
