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.net.*;
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 {
PApplet.main(appletArgs);
}
}
}
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) byfile->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 processing.net, so that looks likejavac -d ./build -classpath /Applications/Processing/Processing.app/Contents/Java/core/library/core.jar:/Applications/Processing/Processing.app/Contents/Java/modes/java/libraries/net/library/net.jar *.java
There’s presumably a more elegant way to do this.