Java

Talk about add-ons and extension development.
Post Reply
marshall8
Posts: 53
Joined: June 13th, 2008, 2:06 am

Java

Post by marshall8 »

Im using this code to call methods from within a .jar file (it works =D> )

Code: Select all

var cl = new java.net.URLClassLoader(
   [new java.net.URL('file:///C:/client.war')]
   );

   var loadedClass = cl.loadClass("siera.Client");
   alert(loadedClass);
   var classInst = loadedClass.newInstance();
   alert(classInst);


It is this next bit that i am finding tricky. Wondered if anyone could help

CODE:

Javascript

Code: Select all


       var mycars = new Array();            //JavaScript wants it to be
        String[] input  = new String[2];   //Java needs it to be


   input[0] = "1.0f";
   input[1] = "2.0f";
   
   var main = classInst.main(input);
   alert('main');


Java

Code: Select all

public static void main(String[] args) {
    ............................................

       float num1 = Float.parseFloat(args[0]);
       float num2 = Float.parseFloat(args[1]);


Thanks for any help
brettz9
Posts: 123
Joined: November 5th, 2005, 9:16 am

Re: Java

Post by brettz9 »

Unfortunately, due to this bug, I don't know how you'd deal with it. It seems one can make other objects, so not knowing much at all about Java, I wonder if you could get around the problem by converting some object holding the string (e.g., subverting java.net.URL or some other object that does work in LiveConnect to use some method to convert its components back into a string within your Java code).

There's yet another bug with LiveConnect which would also give you problems, but if the first bug ever gets solved, you could use something like this:

Code: Select all

function toStringArray (a) { // cf. http://simile.mit.edu/repository/java-firefox-extension/firefox/chrome/content/scripts/browser-overlay.js
   var strArray = java.lang.reflect.Array.newInstance(java.lang.String, a.length);
   for (var i = 0; i < a.length; i++) {
      var str = a[i];
      java.lang.reflect.Array.set(
         strArray,
         i,
         (typeof str == 'string') ? new java.lang.String(str) : str
      );
   }
   return strArray;
  }


The good news with all of this mess, is that somewhere I read that Sun is working on the code or documentation (or both, I forget which) for Java's use in NPAPI, the replacement to LiveConnect, because the FF developers have said that LiveConnect is to be fully deadConnect as of FF 3.1...
marshall8
Posts: 53
Joined: June 13th, 2008, 2:06 am

Re: Java

Post by marshall8 »

Interesting. Supprised anyone replied. I am moving on from this project but I'm sure whoever takes over will find this helpful.

Thanks.
NonSense86
Posts: 13
Joined: December 8th, 2008, 4:53 pm
Contact:

Re: Java

Post by NonSense86 »

Hi, can you please tell me which java version and FF are you using? I need to use java in my FF extension, but I can't get it to work on FF3 and java6 update 11. Which is the latest version combination of FF and java which fits together?
brettz9
Posts: 123
Joined: November 5th, 2005, 9:16 am

Re: Java

Post by brettz9 »

Since update 10, I think you don't need these hacks, you just need to work with the new LiveConnect... See viewtopic.php?f=19&t=807675&p=5240965&e=5240965 and https://jdk6.dev.java.net/plugin2/liveconnect/ . Please let us know if you have success with it (I haven't tried it yet)...
NonSense86
Posts: 13
Joined: December 8th, 2008, 4:53 pm
Contact:

Re: Java

Post by NonSense86 »

Hi,

it works with the Java 6 update 12 and FF 3.0.x
brettz9
Posts: 123
Joined: November 5th, 2005, 9:16 am

Re: Java

Post by brettz9 »

Ok, great, thanks a lot for keeping us all in the loop.

An (apparent) Sun developer has also said that update 12 fixes LiveConnect issues with Firefox extensions. You might be interested in this post at http://forums.java.net/jive/thread.jspa ... 3&tstart=0 . Looks like a lot of the previous LiveConnect bugs may have been fixed too. Now that Sun is taking over (as seems reasonable), it seems much more reassuring that those of us interested in working with Java won't have to depend on the Firefox core developers who didn't want to go near the apparently very convoluted or complicated LiveConnect code (and they had it planned for quite some time to switch to the plugin-neutral and apparently easier-to-maintain NPAPI plugin code). Now thankfully there is both this update that apparently works and detailed documentation (though more Mozilla/extension-specific documentation would be helpful), so things are looking very good...
bijolianabhi
Posts: 4
Joined: May 31st, 2009, 11:11 pm
Location: bijolian, Bhilwara
Contact:

Re: Java

Post by bijolianabhi »

I am still confused that can I use Java Code in my extension. Since someone here saying Java has updated liveConnect and new liveConnect is available.So it means I can use LiveConnect in my extension. But I have studied http://simile.mit.edu/wiki/Java_Firefox_Extension but don't get how to use this code for my extension. may someone here can help me on this issue..
brettz9
Posts: 123
Joined: November 5th, 2005, 9:16 am

Re: Java

Post by brettz9 »

Hi, I've tried expanding https://developer.mozilla.org/en/Java_i ... Extensions . See if the steps there now work for you. Quite a few other people express interest in this as well, so whether you have success following the steps above, or problems, please let me know or otherwise update the wiki.

(Also, if you happen to know how to get Java loaded successfully in Ubuntu (upon which such extensions depend), please let me know as well (as I'd love to be able to test on Linux). The steps at http://www.64bitjungle.com/ubuntu/insta ... a-runtime/ did not work for me.)
bijolianabhi
Posts: 4
Joined: May 31st, 2009, 11:11 pm
Location: bijolian, Bhilwara
Contact:

Re: Java

Post by bijolianabhi »

Thanks brettz9,

I will try these and hope this will work for Firefox 3.5 beta 4 with Java 1.6.0_12. I am going to make a extension that will work on both Windows and Linux so I think your help will be great for me.
well you can see my project at http://www.abhinavtech.org/gsoc/?p=9, may be you can help me on this topic. If you can help me then please post some more matter here or email me at bijolianabhi[at]gmail[dot]com

thanks again..



brettz9 wrote:Hi, I've tried expanding https://developer.mozilla.org/en/Java_i ... Extensions . See if the steps there now work for you. Quite a few other people express interest in this as well, so whether you have success following the steps above, or problems, please let me know or otherwise update the wiki.

(Also, if you happen to know how to get Java loaded successfully in Ubuntu (upon which such extensions depend), please let me know as well (as I'd love to be able to test on Linux). The steps at http://www.64bitjungle.com/ubuntu/insta ... a-runtime/ did not work for me.)
Post Reply