creating a library

Hi all, it is not very clear to me how to create a library. I checked this: But a step by step guide would be more useful if someone know some online example. In particular, how do i pass from my source files to the .jar? Thank you


  • If you use the library template from github then there's an ant script that does the build. You'll need to modify the properties file to suit your environment.

  • edited February 2017

    Firstly - are you clear about how Java works, and what happens in Processing under the hood?

    If so, let's start with this example they provided-

    package libraryexample;
    import processing.core.*;
    public class BasicLibrary {
      PApplet parent;
      public BasicLibrary(PApplet parent) {
        this.parent = parent;
        parent.registerMethod("dispose", this);
      public void dispose() {
        // Anything in here will be called automatically when 
        // the parent sketch shuts down. For instance, this might
        // shut down a thread used by this library.

    The package here is clearly "libraryexample". So the export should be a jar file - libraryexample.jar (at least that's the convention).

    Do you know how to do that? Using any IDE it should be easy enough, but if you're not using one, you can still do it using command line Java, if you know what I mean.

    Now let's assume you have the .jar file. All you need to do is arrange everything into a folder now, and ZIP it. Done. Folder should be like this -

      examples/? - any examples for using the library
  • (You may look at the internal structure of any library you want, for example my own -

  • or use the library template in github, because that's what it's for

  • That's a fair bit of work, @koogs. It just doesn't seem worth the effort, when you just need a little extra work to do everything yourself.

  • Hmmm, actually i don't really know java behind processing, and i just use the processing ide. I know how to export an applet from there, but i assume is a different stuffs?

  • Yep, there a lot more than that much. Have you used Java before? If so, which IDE? Or did you use CMD and Notepad?

  • No, i've never studied Java before. I've integrated some Java tools previously in my script and right now i'm doing some experiment in multi-threading, but that is. I usually write my processing code in the processing Ide or in Sublime-text. And i'm not really planning to study pure Java in the future, i would rather like to migrate soon on node/js. Since i've some experience in Arduino, i was assuming creating a library was about the same, there is quite easy most of the time, but looks like here is another story.

  • I followed the hard method, and I'm not sure there's any "easy" method, so I couldn't help you here. Perhaps if you give an idea of what you need to convert into a library, I could help you.

  • Well, the very specific case is: i'm rewriting some code to running drawing machines, so generating gcode and feeding and arduino via serial. So i guess it would be cleaner organize everything like a library, to be able to use a drawing machine as output for many applications in the future keeping the complexity within the library. But also i'm interested in general.

  • In general? I guess I could help you with some sort of example here. It would be easy if you can download Eclipse (I use Eclipse Mars, you can get the latest if you want), install the Eclipse version for Java using the installer. Then follow these instructions to get the Processing libraries to Eclipse, and get an idea of the changes you'll need to make to make it compatible. Once you do so much, you can progress onto libaries.

  • Thank you, I've just downloaded eclipse and started did the first tutorial: I've to say that the approach help even just this to understand a bit more what is in the background. Probably i'll need to do some more experience on this before thinking about library or starting by creating some easy ones. I'll ask in the future i guess.

  • Ok. Just don't open a new thread, ask questions here.

  • edited April 2017

    Hello, struggling to create and use a simple jar from the command line (Windows). My folder 'shuffle' contains

    package shuffle;
    public class ShuffleList {
        public ShuffleList() {}
        void test() {}

    From the parent folder above shuffle I successfully create ShuffleList.class and shuffle.jar:

    >javac -d shuffle shuffle\
    >jar cvf shuffle.jar shuffle

    I drag shuffle.jar into C:\Users\user\Documents\Processing\libraries\shuffle\library\

    I open Processing 2.2.1 and select Skecth > Import Library > shuffle. It generates:

    import shuffle.*;

    But when I compile, I get:

    The type ShuffleList cannot be resolved. It is indirectly referenced from required .class files.

    Any help greatly appreciated!

  • edited April 2017

    @ottenm Did you try compressing into jar using jar cvf shuffle.jar *.class or jar cvf shuffle.jar shuffle.class? Your method may not work on some systems.

Sign In or Register to comment.