I would like to continue using Processing for my code/design ideas but I'm having an incredible amount of trouble with getting external files (or data files) into my sketches exported as applets and Mac OS X applications due to discrepancies with the handling of the variable sketchPath. Since dataPath(), dataFile(), sketchFile() etc all use this one variable, sketchPath, I've found that its definition is at the core of my problems.
When running as an Mac app the sketchPath variable cannot be relied upon and most certainly does not use the data folder that is compiled into the .jar residing inside the .app contents.
When running as an applet, either on local machine or on my web server, sketchPath is a null and causes headaches. I've secured the applets so this is not the issue. In the applet source sketchPath is set to:
sketchPath = System.getProperty("user.dir");
Could it be that in recent changes to Java, this is no longer a valid way to set sketchPath for exported applet sketches?
I've not found any help searching the forums or the web and it seems I am alone. Providing code examples are not relevant here since simply calling println(sketchPath); from setup will produce null.
Advice, help, or corrections to the source would be of huge value to my project which requires the loading of word.txt files:
If you agree that this is a processing source code issue, or test and get different results, or you have different experiences using sketchPath in applets or Mac applications, then please, post your comments or recommendations here.
Why do you use sketchPath at all? In general, just put your data files in the data folder, just give the file name to the loadXxx() functions, and it should work, from the PDE and from applets, without any gymnastics. Indeed, in an applet, I think that System.getProperty("user.dir") is null, unless, perhaps, if the applet is signed. But an applet doesn't need to know sketchPath, it won't pull the files from the user dir (which probably doesn't have the correct assets, in general), but from the jar itself.
If these lists are hard-coded (that's probably the case in an applet), you can just put the list of files in an array, directly in the code. As I wrote, the files are added to the generated jar and frankly, I am not sure if there is a simple way to list them there, from an applet. Some techniques working well on the user's computer just fails in an applet.
While I really wanted the desktop PDE version of the sketch to be able to dynamically read in whatever fonts and words files the user has placed into the data folder, it seems this is not nearly as feasible for applets or apps. My workaround was to create a .txt file holding the list of fonts that have been placed in the fonts folder and then to use that list to load in the fonts. I also abandoned the ability to choose or dynamically create words lists and will perhaps come back to this one day.
It's unfortunate that dataPath() does not also return the path to the data folder that's inside the .jar when a sketch has been exported as applet or mac app. What an elegant solution this would be.
Leave a comment on josephknight's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic