MozillaZine

Using java in an Extension, how ?

Talk about add-ons and extension development.
valorian
 
Posts: 8
Joined: May 30th, 2008, 2:58 am

Post Posted May 30th, 2008, 3:14 am

Hi,

im currently reading into extension-development.

now i got stuck with integrating a Java Package into it. (to use existing code!, maybe later to protect non-free Code)

My Code (overlay.js):
--------------------------------------------------------
try {
var cl = new java.net.URLClassLoader(
[ new java.net.URL('http://localhost/greeting.jar') ]
);
var aClass = java.lang.Class.forName("com.myTest.Firefox.Greeting", true, cl); // Line throwing Exception
var GO = aClass.newInstance();
var aStaticMethod = aClass.getMethod("getGreeting", []);
var greeting = aStaticMethod.invoke(GO, []);
alert(greeting);
}
catch (err) {
alert(err);
return;
}
--------------------------------------------------------
resulting in a "InvocationTargetException"

which looks like it can't load the .jar

The Jar-File is located correctly and it's code has been checked by another callable .jar
still i have to change the URL to use a .jar included in the extension itself.

i looked around in google, developer.mozilla.org, but can't find working examples or hints.
Most stuff in found is related to firefox 0.9 or 1.0.

Any hint, information, example ?

thanks

RaiseMachine

User avatar
 
Posts: 1764
Joined: December 6th, 2004, 6:05 pm
Location: England

Post Posted May 30th, 2008, 4:09 pm

Checkout: http://simile.mit.edu/wiki/Java_Firefox_Extension

Yes it says 0.9 or 1.x but the extension does work for me in FF 2.0.0.x
"Doesn't the idea of making nature against the law seem to you a bit... unnatural ?" - Bill Hicks
"Money is the Schrodinger's Cat of economics." - Robert Anton Wilson
"It's not a bug, it's two features having a fight in the pub car-park." - Me

valorian
 
Posts: 8
Joined: May 30th, 2008, 2:58 am

Post Posted June 1st, 2008, 11:10 pm

Thanks

but in that example is no description 'what' is really required to get it work.
And there is that "nsIHelloWorld.xpt", of which i don't know if it's required. In my example i didn't use a xpt-File (and i didn't found clear documentation where it's needed and where not)

any other sources ? (or did i miss some important documentation there)


thanks

RaiseMachine

User avatar
 
Posts: 1764
Joined: December 6th, 2004, 6:05 pm
Location: England

Post Posted June 2nd, 2008, 4:08 am

XPT files are XPCOM type libraries.

http://developer.mozilla.org/en/docs/In ... _Libraries

The type library is a binary representation of an interface or interfaces. It provides programmatic control and access of the interface, which is crucial for interfaces used in the non C++ world. When components are accessed from other languages, as they can be in XPCOM, they use the binary type library to access the interface, learn what methods it supports, and call those methods.

http://developer.mozilla.org/en/docs/XPIDL:xpidl
http://www.mozilla.org/scriptable/typelib_file.html

CheckOut the source code via Subversion and explore it as per the article, that's how I learned. :)

Direct link to version 2 of the XPI: http://simile.mit.edu/repository/java-f ... -2.0.0.xpi
SDK (1.8.1.x): ftp://ftp.mozilla.org/pub/mozilla.org/x ... ontrib/sdk
SDK (1.9.0.0): ftp://ftp.mozilla.org/pub/mozilla.org/x ... .9.0.0/sdk

EDIT: Updated SDK link
"Doesn't the idea of making nature against the law seem to you a bit... unnatural ?" - Bill Hicks
"Money is the Schrodinger's Cat of economics." - Robert Anton Wilson
"It's not a bug, it's two features having a fight in the pub car-park." - Me

csam0003
 
Posts: 68
Joined: February 24th, 2009, 4:05 pm

Post Posted March 30th, 2009, 3:37 am

Hi guys,

does anyone know how to convert the chrom path to a file path as
urlArray[0] = new java.net.URL('chrome://sharenotes/content/HelloWorldApp.jar'); is not working!!!


thanks

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest