Re: "Proper" way to Access Java from javascript
sam keen <[email protected]> Sun, 2 Dec 2007 17:35:04 -0800 (PST)
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <2503e2da-3771-4ce9-88b1-0f1537e51644__23418.5503134087$1196645752$gmane$org@b40g2000prf.googlegroups.com> |
On Dec 2, 1:55 pm, Brett Zamir <[email protected]> wrote: > sam keen wrote: > > liveconnect: > > - is this true "LiveConnect may be removed from Mozilla 2.0 according > > to this post by Josh." > > I'd sure like an answer on this one too....> - for statements like var red = new Packages.HelloWorld(); where do > > you place your jar file so it can be found? > > I believe that Packages will not allow you access to your own packages > (I learned this the hard way). Try using URLClassLoader. Seehttp://developer.mozilla.org/en/docs/Talk:Java_in_Firefox_Extensionsfor > examples of usage with LiveConnect... If the files are local you can use > the file:/// protocol... I needed to put the loader (called via > LiveConnect) in global scope for my own extension that uses this, so > that it would not attempt to load multiple times and thus cause errors > (I guess with DLL files)... > > And for my case of finding my own extension directory to find the jar > file, I did, with the bold portion at the end being my own extension > identifier: > > var path = > Components.classes["@mozilla.org/file/directory_service;1"].getService( > Components.interfaces.nsIProperties).get("ProfD", > Components.interfaces.nsIFile).path; // Get path to user profile folder > var extpath = path+'/extensions/*[email protected]/'*; > > One problem with this though is that "Classes loaded by a URLClassLoader > have whatever permissions are granted to their java.security.CodeSource > by the system java.security.Policy" (Java in a Nutshell, p. 582). You > need to either have permission granted to the jars in a user home > .java.policy file, or use the trick (a good trick) in the Java Firefox > extension to get permissions granted for your app. I'm doing the former > now during testing, but hope to use the Java Firefox extension (XPCOM) > approach in the future (which also gives the benefit of getting one > single Java object for all windows)... > > One other tip: the try-catch blocks in Javascript do not work for me--I > needed to perform them within Java (I built wrapper methods to make this > expandable). > > best wishes, > Brett thanks for the info Brett, I did figure out java.net.URLClassLoader (using a complete file path). I'll try your code out for getting the extension path (thanks for the snippet) And yes I did hit the security policy wall. All my java code works until it gets to interacting with the Runtime object. Thanks for the .java.policy reference, I'll see if I can get that working and then move onto the Java Firefox ext hack as you are. regards, Sam