Installing Java library

edited September 2017 in Using Processing

I want to install an external Java library (the Apache math library). After downloading it from Apache, which directory should I move it into so that I can import it into my sketch? I'm using the Processing IDE.



  • edited September 2017

    Quickest fix is to simply drag & drop the ".jar" files into Processing's IDE (PDE).
    Then it's gonna create a subfolder "code/" and automatically put those ".jar" files in it. *-:)

    For other solutions, go here:

  • Thanks. I read that page, but it wasn't very clear to me. I would like to install the library and have it available for any sketch, not just one, if that's possible. But I tried what it says here, renaming the jar file so the name contained only letters and numbers (ie, "CommonsMath3.jar"):

    Another example: you want to use the Apache Common Collections library, which is a plain Java library (ie. not designed for use with Processing). The zip file contains a folder named commons-collections-3.2.1 with various files in it, including one: commons-collections-3.2.1.jar

    You have to create the libraries/ApacheCommonCollections/library folder (the middle name can vary, but must have only letters and numbers) where you put the jar file renamed along the folder name (here, ApacheCommonCollections.jar, then).

    Alternatively, if you need this library for only one sketch, you can just drag'n'drop the jar file on the PDE, it will put it in a folder named code in the sketch folder (you can also create the folder manually and put the jar file there yourself). This also works, of course, for regular Processing libraries. This solution isn't optimal if you plan to use the library in several sketches, as it will duplicate the library, taking up space and making difficult a possible upgrade.

    However, when I added the import statement below, I got the error message "The import CommonsMath3 cannot be resolved":

    import CommonsMath3.*;

    I verified that there was a sub-folder called "code" in my sketch folder containing the jar file, so I'm not sure why Processing was unable to import it. I'm running Processing v3.3.6 on Windows 7.

    In any case, I'd like to be able to add the library to the Processing installation rather than each individual sketch, but that doesn't seem to work either. Is any one using the Apache math library in Processing?

  • edited September 2017 Answer ✓

    I found the problem. I needed to add another sub-folder call "library" underneath the sub-folder "CommonsMath3", then put the jar file in that sub-folder. So the directory structure now looks like this:


    Once I'd done that, I started the IDE again and went to "Import library...". Lo and behold, the math library now appeared under "Contributed" and I was able to import it; now it seems to be working.

    Here's the link to a question someone posted in StackOverflow which finally helped me to figure it out:

    After re-reading the instructions in the Processing github (, I realize that I missed the extra "library" sub-folder, but maybe it would help others if there was an example of the required directory structure, like the one I provided above. Maybe it would save other people some time (when I googled for this issue, I found many people having the same problem).

    Anyway, thanks for your help, GoToLoop.

  • Answer ✓

    @dfkettle Thxs for sharing your solution.


  • OK. In Documents/Processing have Libraries folder. in Libraries create folder nameX (your library). into folder nameX create folder Library and src. in Library copy the jar file and in the src copy the src of your library.

    Crea en mis documentos/processing/Libraries una carpeta llamada miLibreria. dentro de miLibreria crea la carpeta Library y la carpeta src. dentro de Library copia el archivo jar y en src la estructura de directorios del codigo en java (org.opencv.XXX). a mi me funcionó.

    al pendiente.

Sign In or Register to comment.