0

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

4
  • 8
    java != javascript Commented Oct 28, 2010 at 10:17
  • do you run your javascript from inside a JVM (i.e. by using Apache Rhino)? Commented Oct 28, 2010 at 10:23
  • Why you need to use it with JavaScript. Commented Oct 28, 2010 at 10:43
  • thanks for your time. I'm using Jboss as the server. the problem is that i want to call some webServices written in java.and use Ext Js as the UI. Ext Js only supports Java Script and therefor i am trying to import a .Jar file which includes Classes having some methods that call web Services. Commented Oct 28, 2010 at 10:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you my friend,since I'm newbie to both java and java script I would appreciate if you send me a sample...calling a web service in java script. (I used to work with c# desktop App)
You probably wanna look at XMLHttpRequest(). But I fear that it won't be useful if you don't know JavaScript.
0

There's another way to think of this. If you are trying to indeed write a JavaScript application with a Java backend, you probably would struggle to get all the support you need from the JavaScript community. But if you think of it as a Java application with a JavaScript frontend, all of a sudden, you have lots of options. I'm sure SpringBoot alone could give you many complete solutions. Here's one for React.js.

Furthermore, feel free to look at some of these new frameworks I found at Raygun.com. I haven't had the opportunity to use any of these myself but I believe one in particular seems to have the make up of what you're looking for. It was listed as Vaadin.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.