问题描述
我想在Java脚本中导入一个.Jar文件,
Jar文件中有一个我想在Java脚本中使用的类,这里是我找到的代码,但无法使其工作然而!
var cl = new Packages.java.net.URLClassLoader(
[
new Packages。 java.net.URL('http','My Ip','8080','Hello.jar')
]
);
var aClass = Packages.java.lang.Class.forName(PackageAddress.Hello,true,cl); // Hello是公共类名称
var aStaticMethod = aClass.getMethod (SayHello,[]); // SayHello是一个返回字符串的公共方法
var greeting = aStaticMethod.invoke(null,[]);
alert(问候);
任何建议都将受到赞赏
你没有。
JavaScript不是Java。
尝试在JavaScript ExtJS代码中使用Java代码将是一个完全的过度杀伤,要求用户在他们的浏览器中安装Java插件,并且由于Java插件而放慢浏览器的速度。当然,假设它可能有效(我不确定)。
你想从你的JavaScript代码调用webservices吗? (重新)用JavaScript编写webservice-calling。这不仅是最好的解决方案,而且我非常确定它比尝试设置Java applet并尝试与之交互需要更少的工作。 / p>
I want to import a .Jar file in Java Script,there is a Class in the Jar file which i want to use in Java script,and here is a code i found but couldn't get it work yet !
var cl = new Packages.java.net.URLClassLoader(
[
new Packages.java.net.URL('http','My Ip', '8080', 'Hello.jar')
]
);
var aClass = Packages.java.lang.Class.forName("PackageAddress.Hello", true, cl);// Hello is a public class name
var aStaticMethod = aClass.getMethod("SayHello", []);//SayHello is a public method returning a string
var greeting = aStaticMethod.invoke(null, []);
alert(greeting);
Any Suggestions would be appreciated
You don't.
JavaScript is not Java.
And trying to use Java code within your JavaScript ExtJS code will a complete overkill, requiring users to have Java plugin installed in their browsers, and slowing down their browsers because of Java plugin. Of course, supposing it might work (and I'm not sure about that).
You want to call webservices from your JavaScript code? (Re)Write the webservice-calling in JavaScript. Not only this is the best solution, but I'm pretty sure it will require less work than trying to set up a Java applet and trying to interact with it.
这篇关于如何在Java Script中导入.Jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!