Loading...
Logo
Processing Forum

Sketches sharing classes

in General Discussion  •  Other  •  2 years ago  
Is it possible for separate sketches to make use of the same classes without having to copy those classes into each sketch?  I am co-developing separate sketches and the shared classes they use at the same time so it would be inconvenient to have to make it into a jar file library and import it.  But keeping multiple copies around means I have to update each one every time I update the classes.  Does anyone have any advice on how to best stay organized?

Replies(11)

Do the sketches really need to be separate? Could you have different 'modes' of the same sketch?

D.

Processing user on Google Plus? http://gplus.to/calx
That wouldn't really work very well.  I want to make many different sketches, each with their own main method.  The classes the sketches will reference are more a library than anything, I just don't want to have to constantly repackage them since I am developing them at the same time.
I asked that a long time ago, and the topic resurfaces here and there... It would be nice to be able to have common .pde or .java files in a kind of source library, automatically included on demand. This remains a feature request...
If you work on a Unix-based system (Mac OS X or Linux), one solution is to create symbolic links.

Put all your .pde files that are common to your sketches into a folder common.

Open a Terminal or a shell and change to the sketch folder for which you want to include a common-class file. Type

ln -s ../common/your_common-class_file.pde .

(don't miss the point at the end of the line before)

So you can have all your common class files at one place, and all your sketches will be updated when you change them.
That would work really well but unfortunately I am on Windows.  Would windows shortcuts do the trick.  Is there any add-on to Windows that would do symbolic linking?
Just try it out yourself. Create a shortcut of a .PDE file, put it into another sketch folder, and open the sketch in Processing.
If it works, you should get an additional tab.

Edit: Please let us know of the result.
There is Junction for Windows:
http://technet.microsoft.com/en-us/sysinternals/bb896768

The only thing I don't like about doing it on Windows, though, is I don't think you get any indication that a file or directory is linked (XP at least).
Shortcut links won't work.
Junction is for directories, not for files.
There are ways to do symbolic links, I think, but as said, it is hard to identify them once they are made.
I just made a hardlink with UnxUtils, and a Wikipedia article lists some other tools.
I just found out XP has a built in command to make "hardlinks" that works for files. From cmd.exe (start -> run -> cmd) try:
fsutil hardlink create path/to/destination/file.pde path/to/source/file.pde
The first argument being the non existing file.
Another confusing this though, I don't know if they take up space at both locations or what.
Thanks for the info. I've been also trying to do diff sketches but got many problems. Will try these procedures and will let you know of the outcome.
 
Thanks for the idea!
Windows 7 has 'mklink' for making symbolic links.
Can be run from commandline, but is backwards from linux concering arguments.

mklink <newlink> <filetopointto>

I believe.

Run just mklink, and you'll get the help info.