# How to create a library from projects

**URL:** <https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151>\
**Category:** Libraries\
**Created:** [March 5, 2023, 4:47pm UTC](https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151 "2023-03-05T16:47:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![urlxd](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@urlxd](https://discourse.processing.org/u/urlxd)\
**Post date:** [March 5, 2023, 4:47pm UTC](https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151/1 "2023-03-05T16:47:04Z")

</div>

hello, when creating a larger project, I ran into the problem that everything is in one project. I would like to create classes and use it in another project as a library. If there is such an opportunity in “Processing”, then tell me how to do it.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 5, 2023, 6:37pm UTC](https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151/2 "2023-03-05T18:37:59Z")

</div>

> [@urlxd](#):
>
> I would like to create classes and use it in another project as a library.

Hello,

Take a look here:

> **[Home](https://github.com/benfry/processing4/wiki)**
>
> Processing 4.x releases for Java 17. Contribute to benfry/processing4 development by creating an account on GitHub.

Take a look at the use of tabs in the Processing IDE:

> **[Environment](https://processing.org/environment/)**
>
> The Processing Environment includes a text editor, a compiler, and a display window. It enables the creation of software within a carefully designed set of constraints.

I have a number of files that I simply drag and drop into Processing sketch that contain methods and classes for reuse. These will be separate tabs.

Related:  
[https://github.com/processing/processing4/issues/248](https://github.com/processing/processing4/issues/248)

`:)`

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [March 5, 2023, 7:00pm UTC](https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151/3 "2023-03-05T19:00:02Z")

</div>

Hi

Some hints

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/21049/creating-a-library.html)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

> [@Loading Class In Data Folder?](https://discourse.processing.org/t/loading-class-in-data-folder/40546):
>
> Is there a way to load a class stored in the ‘data’ folder? No problem if the class is under a separate tab in the main app, but what if it is stored in the data folder?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [March 6, 2023, 8:48am UTC](https://discourse.processing.org/t/how-to-create-a-library-from-projects/41151/4 "2023-03-06T08:48:59Z")

</div>

Hi @urlxd,

imo this is not really a processing question, but rather a java one…  
Also don’t know what OS you are working on so assuming Windows by using processing java mode.  
Further not knowing if you want to create a contributed library or only some function you want provide for yourself.

if first one, look here:

> **[Library Basics](https://github.com/benfry/processing4/wiki/Library-Basics)**
>
> Processing 4.x releases for Java 17. Contribute to benfry/processing4 development by creating an account on GitHub.

if the latter you can build a simple library depending on your java knowledge yourself.

_ **Just a demonstration not a recommendation 🙂** _

1. create a directory structured for your java files and add some functionallity

> _In a command prompt this could look like:_

> ```auto
> c:\> mkdir c:\mylib\my\tools
> c:\> cd /D c:\mylib
> c:\mylib>
> 
> ```

* * *

1. create your java file(s) ie:

> first file: c:\mylib\my\tools\MyStaticTools.java  
> _ie: provides static methods for use as an example_

> ```auto
> package my.tools;
> 
> public class MyStaticTools { 
> public static int addValues(int a, int b) {
> return a+b;
> }
> 
> public static int subValues(int a, int b) {
> return a-b;
> }  
> }
> 
> ```

> second file: c:\mylib\my\tools\MyClassTools.java  
> _ie: provides class methods for use as an example_

> ```auto
> package my.tools;
> 
> public final class MyClassTools { 
> public int multValues(int a, int b) {
> return a*b;
> }
> 
> public int powValue(int a) {
> return a*a;
> }  
> }
> 
> ```

1. back in the command prompt (assuming you are already in the directory from step 1) type :  
_assuming `c:\processing` is the directory where you’ve installed processing_

- The first command build `.class` files from you `.java` files into a `bin` directory

> ```auto
> c:\mylib>c:\processing\java\bin\javac.exe -d bin my\tools\*
> 
> ```

- The second command build a structured `.jar` library from your `.class` files

> ```auto
> c:\mylib>c:\processing\java\bin\jar.exe -cf mytools.jar -C bin my
> 
> ```

As a final result you should see a `mytools.jar` file in the directory.

The content of the `mytools.jar` can be verified afterwards by command

> ```auto
> c:\mylib>c:\processing\java\bin\jar.exe -tf mytools.jar
> 
> ```

And should look like:

> ```auto
> META-INF/
> META-INF/MANIFEST.MF
> my/
> my/tools/
> my/tools/MyClassTools.class
> my/tools/MyStaticTools.class
> 
> ```

Afterwards drag and drop that file onto your PDE Window. This will create a folder named `code` in your sketch folder and loads the jar file for usage. If that all was successfully you can then use the provided functions in your sketch (minimalistic sketch example):

```auto
import my.tools.MyStaticTools;
import my.tools.MyClassTools;

println(MyStaticTools.addValues(1,2));

MyClassTools mytools = new MyClassTools();
println(mytools.powValue(2));

exit();  

```

The console output:

> 3  
> 4

Cheers  
— mnse

EDIT:: fix typo
