Re: LiveConnect and/or JavaXPCOM
Greg Bowyer <[email protected]> Mon, 01 Dec 2008 20:39:20 +0000
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <[email protected]> |
poorboywilly wrote:
> Hi guys, I'm having a bear of a time here trying to work with some
> Java code. I've got an extension going in Firefox (the XUL,
> JavaScript, CSS is great) and an XPCOM component in C++ (my best
> language) to do most of the heavy lifting. The last thing I need to
> do is interface with a Java library (Apache's Nutch) for a few calls.
> Having discovered JavaXPCOM and LiveConnect this seemed like cake, but
> the documentation is definitely spotty so when my own fiddling doesn't
> work I can't find anywhere to turn.
>
> First, I already implemented an XPCOM component in C++ so I decided to
> do a Java XPCOM component. I have the XULRunner 1.9 SDK which
> includes the Java interfaces for all the nsISupports and so forth. I
> implemented ISupports, IModule, IFactory in a few Java classes as well
> as defined my own interface in an IDL, compiling the idl both to
> a .java file and a typelib. All the JavaXPCOM stuff I can find deals
> almost entirely with calling XPCOM components from Java code, I cannot
> find info on a Java component. I've tried putting the raw class files
> (and typelib) in the Firefox/components directory, as well as a .jar
> of my classes in there and Firefox won't seem to find the component
> like it does my C++ component (using XPCOMViewer extension). What am
> I missing with the JavaXPCOM?
>
As far as I am aware, you cannot currently embed java xpcom components
into xulrunner, rather (as you have seen you have to run the event loop
from java). Javier Pedemonte, who I am _sure_ will respond to this with
far better information than myself is the lead for xpcom and was, last
time I heard was working on getting java to be called from normal
xulrunner builds.
I think the bug tracking this is
https://bugzilla.mozilla.org/show_bug.cgi?id=299263 but I am not sure
what state it is in
> Then, I stumbled across LiveConnect, and I could seemingly create the
> Nutch Java classes in my JavaScript extension code with a simple "new
> Packages.foo.bar.Class()" statement. I was able to create a "new
> java.lang.String("foo")", which had me excited. But the only
> apparently useful documentation I can find on LiveConnect is using it
> to call code in applets (e.g. https://jdk6.dev.java.net/plugin2/liveconnect/).
> Well, I don't need an applet, I just need to call an arbitrary Java
> package, and not even from a website, from an extension. Perhaps I'm
> asking for too much? I found a vague reference to placing the
> desired .jar in the jre/lib/ext folder, which I did, but when I do
> that the LiveConnect statement just seems to freeze the browser. Can
> LiveConnect be used in this way?
>
LiveConnect is initially intended for use with applets and webpages, and
really works in mozilla due to the fact that xul is treated largly as a
target for rendering (like html). Using it outside of webpages is made
somewhat harder due to classloading hassles (and I am assuming that as
you are using nutch you are going to run into classloading and sandbox
issues).
That said the smile guys at mit have done a lot of work with liveconnect
and should be able to point you in the right direction.
(http://simile.mit.edu/wiki/Piggy_Bank)
Mozilla Developer Center also has a bunch of documentation here that
should apply fairly accuratly to what I think you are trying to do
http://developer.mozilla.org/en/docs/Java_in_Firefox_Extensions
However to annoy you live connect is as far as I am aware doomed in
mozilla 2 to being removed, see here
https://bugzilla.mozilla.org/show_bug.cgi?id=397080
and
http://boomswaggerboom.wordpress.com/2007/04/16/javaplugin-cleanup-for-mozilla-20/
> I would appreciate ANY help anyone can throw at this.
>
> thanks,
> --Jason