My new tiny library "does not exist"

Hi folks –
I’m trying to wrap some code up into a little personal library because I want to write a bunch of sketches that refer to it and I don’t want any of them to get out of sync if I need to change something. (Also, I’d like to distribute it to some labmates and make it very easy for them to use.)

So I finally managed to generate a .jar*, I believe I’ve got it in the right place –[sketchbook]/libraries/[name]/library/[name].jar– and I’ve restarted Processing and even the whole computer. However, when I add import [name];, Processing tells me that the “package does not exist.” Interestingly, my library does show up in the import library menu, but when I select it, only a blank line is added.

I’m suspicious that maybe I didn’t do something right in generating the .jar. My code is just a single class, in a single .java file which looks like this:

import processing.core.*;
import java.util.ArrayList;

public class Name {
    // lots of code here

    static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "name" };
    if (passedArgs != null) {
      PApplet.main(PApplet.concat(appletArgs, passedArgs));
    } else {

The .jar seems to work okay if I include it in the code directory of a given project, but I’d really like for it to be a centrally-accessible library for updating reasons.

Does anyone have any tips?

*tips for anyone following in my footsteps, since I wasn't able to find some of this by googling:
  • you can generate “non-Processing” Java (expand Processing’s convenience syntax and add that static public void main(String[] passedArgs) thing) by file->export to a standalone app, then “view package contents” to find the .java
  • you’ll need to preface any Processing-specific functions with the class they come from, which is probably PApplet; e.g. “concat()” -> “PApplet.concat()”
  • in running the javac, you’ll need to refer to all the Processing jars you’re using in a classpath; for me, I’m using processing.core and, so that looks like javac -d ./build -classpath /Applications/Processing/ *.java There’s presumably a more elegant way to do this. :stuck_out_tongue:

possibly this helps:

1 Like

I did read both of those – I wouldn’t have made it this far without them :slight_smile: – but I’m not seeing where I’m diverging from the instructions. I also tried to read through this forum thread: Including shared pde files across projects (though I got a little lost in which things did and did not work) and I think what I have follows the example in

But I’m not in any sense a Java developer so it’s entirely possible I got the “building the .jar” part wrong, since that’s the part that’s glossed over in the Wiki entry. What I did was run, in a directory containing only

javac -d ./build -classpath /Applications/Processing/  *.java
cd build
jar cvf name.jar *

Do I maybe need other things in that directory when I make the .jar?

1 Like

Aha, solved! I needed a package name; at the top of my .java.