External libraries with Processing
I'd like to link to external libraries with Processing without actually having to compile them down to a jar file and then put them in my Processing system folder. Ideally in the Processing config file you could set up locations to look for additional libraries, and then you could just put the uncompiled classes in those directories and they would be added into your project automatically, or with an import statement -- similar to how Python and many other l开发者_StackOverflow中文版anguages do it.
I suppose I could make a script that would javac the source, jar it, and copy it into my Processing libraries folder, but then I'd have to write my libraries in straight Java, and I'd like to write these libraries in Processing syntax.
Thoughts?
It should be possible to add your source files into the code folder of your Processing sketch, or try to paste the files into new tabs with the .java extension in the Processing IDE, but I'm not 100% sure this will work with the more recent versions. This worked a couple of years ago, but AFAIK Processing now uses the common Processing/libraries path for external code.
As Andreas advises, the easiest option is to use eclipse. If you like the easy peasy setup in Processing (including application export), I would recommend eclipse+the proclipsing plugin. Proclipsing is v. easy to setup and it allows you to easily create sketches and export them. The other great advantage is that in eclipse you'll also have auto complete for 3rd party code + among other cool feature eclipse has to offer.
The only difference from syntax in the Processing IDE vs. eclipse is that you need to add you're code to a class that extends PApplet and add public in front of setup(), draw(),etc. but again, auto complete and the proclipsing template will make this trivial. Other than this tiny detail, feel free to use the syntax as you're used to.
Goodluck!
Click on Sketch - import library
If you're most comfortable with the Processing IDE and wish to continue using, its include abilities are quite limited. Additional .pde files in the sketch folder do become additional tabs, and classes in those files/tabs are equivalent to the main sketch .pde file, so you could attack your problem from this angle.
Make a sketch folder for each "library" of related classes you wish to include in other sketches, put all of the code in the primary .pde file, and hard link that file into the sketch folders of each sketch that will consume it. Keep in mind that each of these instances of the .pde file are actually the same file, and that modifications to any will modify all. You would likely want to take measures to keep versions separate if it evolves over time.
精彩评论