在Firefox插件中执行jar文件

时间:2015-03-31 21:19:50

标签: java javascript firefox firefox-addon

我尝试创建Firefox插件,在环境充满后执行java程序(右键单击img并在菜单中选择) - RunExe函数存在问题我相信,我不知道如何处理。

临时java程序:

public class Test {

public static void main(String[] args) throws IOException {
    String imageUrl = "http://www.avajava.com/images/avajavalogo.jpg";
    String destinationFile = "E:/image.jpg";

    saveImage(imageUrl, destinationFile);
}

public static void saveImage(String imageUrl, String destinationFile) throws IOException {
    URL url = new URL(imageUrl);
    InputStream is = url.openStream();
    OutputStream os = new FileOutputStream(destinationFile);

    byte[] b = new byte[2048];
    int length;

    while ((length = is.read(b)) != -1) {
        os.write(b, 0, length);
    }

    is.close();
    os.close();
    }
}

Firefox插件:

var {Cc, Ci} = require('chrome');
var contextMenu = require("sdk/context-menu");
var menuItem = contextMenu.Item({
    label: "Szybkomemator",
    context: contextMenu.SelectorContext("img"),
    contentScript: 'self.on("click", function (node) {' +
            '  var text = node.getAttribute("src");  ' +
            '  self.postMessage(text);' +
            '});',
    onMessage: function (params) { //Later I'll change this
        RunExe(params); 
    }
});

function RunExe(params){

    var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    file.initWithPath("‪E:\\test3.jar");

    var oProcess = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
    oProcess.init(file);

    var args = null;
    var argsLen = 0;
    if (params) {
        args = [params];
        argsLen = 1;
    }

    oProcess.run(false, args, argsLen);
}

我使用类似的代码来运行.exe并且它有效,但是使用.jar我收到了这个(Paths肯定是好的):

console.error: addon:
Message: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_
FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]"  nsresult: "0x80520001 (NS_
ERROR_FILE_UNRECOGNIZED_PATH)"  location: "JS frame :: resource://gre/modules/ad
dons/XPIProvider.jsm -> jar:file:///c:/users/evanec/appdata/local/temp/tmpfcgnum
.mozrunner/extensions/jid1-JI0fwfYhRixYag@jetpack.xpi!/bootstrap.js -> resource:
//gre/modules/commonjs/toolkit/loader.js -> resource://jid1-ji0fwfyhrixyag-at-je
tpack/addon/lib/main.js :: RunExe :: line 18"  data: no]
Stack:
RunExe@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///c:/users
/evanec/appdata/local/temp/tmpfcgnum.mozrunner/extensions/jid1-JI0fwfYhRixYag@je
tpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js ->
resource://jid1-ji0fwfyhrixyag-at-jetpack/addon/lib/main.js:18:0
menuItem<.onMessage@resource://gre/modules/addons/XPIProvider.jsm -> jar:file://
/c:/users/evanec/appdata/local/temp/tmpfcgnum.mozrunner/extensions/jid1-JI0fwfYh
RixYag@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/load
er.js -> resource://jid1-ji0fwfyhrixyag-at-jetpack/addon/lib/main.js:11:5
emit@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///c:/users/evane
c/appdata/local/temp/tmpfcgnum.mozrunner/extensions/jid1-JI0fwfYhRixYag@jetpack.
xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resour
ce://gre/modules/commonjs/sdk/event/core.js:97:8
workerMessageReceived@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:
///c:/users/evanec/appdata/local/temp/tmpfcgnum.mozrunner/extensions/jid1-JI0fwf
YhRixYag@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/lo
ader.js -> resource://gre/modules/commonjs/sdk/context-menu.js:462:13

0 个答案:

没有答案