Hello,
I managed to successfully deploy simple clojure application with java
web start. I will share my experience here, because I had some
problems with granting enough security privileges to run clojure
application as java web start applet (getting AccessControlException)
and I did not find complete solution in group's archive. Editing
java.policy file was not an option because I wanted to share my
application with users who might not understand java policies at all.
My application is written entirely in clojure except one java class
with static main method. This main method looks like this:
public static void main(String[] args) throws Exception {
RT.init();
// load clj resource
loadFromClasspath("alphabet/alphabet.clj");
// get clojure fun
StringReader sr = new StringReader("clojure-main");
PushbackReader r = new PushbackReader(sr);
IFn clojureFun = (IFn) Compiler.eval(LispReader.read(r, false,
null, false));
// call clojure fun
clojureFun.invoke();
...
So all I do here is: load clojure source file, get clojure main
function and then call it.
To run it as java web start applet I had to:
1) Include <security><all-permissions/></security> element in
my .jnlp file.
2) Sign clojure.jar and my application .jar files. Instructions found
on
http://www.dallaway.com/acad/webstart/ were helpful
3) Put the following code in static section in class with the static
main method:
static {
Policy.setPolicy( new Policy() {
public PermissionCollection
getPermissions(CodeSource codesource) {
Permissions perms = new Permissions();
perms.add(new AllPermission());
return(perms);
}
public void refresh(){
}
});
}
Third step was necessary because all permissions from first step were
granted to javaws classloader only and clojure creates it's own
classloaders, at least I think so :).
ps. This is a simple alphabet typing swing application, it measures
your time to type whole alphabet. Time starts with typing letter a and
ends with letter z. Space resets the game. It may be run with javaws
from here:
http://www.pasza.org/files/alphabet/alphabet.jnlp
clojure code may be found in this jar:
http://www.pasza.org/files/alphabet/alphabet.jar