Hi Christian, Christian Sprecher schrieb: > Hi all > > Maybe a silly question: what is the best way to create reusable scripts? > By reusable I primarly mean for related resources.
Well, if it just for executing the same scripts to handle requests to different resources, you might want to consider using resource super types. > > I am currently aware of 3 possibilites: > 1) the *.esp way with the load() function, which afaik loads & evaluates > a script > 2) the *.jsp way with compilation and then execution Well, in JSP you have you have two options: include pieces of code (fragements) upon JSP build time (<%...@include>) and RequestDispatcher based include with <jsp:include>. I assume you mean the former here, right ? > 3) the OSGI way with bundles and services and stuff This is fundamentally different from the first two options, but it has one big advantage: It is the ultimate option to be really reusable independent on whatever scripting language to you choose to handle resource requsts. > > Now, I would like to keep DRY and use some common functions, and all > with Groovy scripts. As far as I know (and this is not too far), all 3 > possibilities would be possible with Groovy, and all 3 might make sense. > Currently I am tending towards the jsp-solution: I would like to use > compiled java classes whereever possible and still use the fast round > tripping of the esp-way. > > What do you think: are my assumptions right? How would you tackle the > jsp way? I don't think, I know enough of groovy as to answer this question. As you said, it all boils down to how a specific scripting language supports code reuse. ESP/ECMA currently supports load() only (though there semes to be motion out there in the wild in this respect around the ServerJS initiative (https://wiki.mozilla.org/ServerJS)). JSP supports <%...@include> and <jsp:include>. All share the ability to reuse Java objects/code which we support by means of the SlingScriptHelper object provided. Hope this helps -- or maybe I am missing your point ;-) Regards Felix > > Cheers > > Christian > >