如何使用Rhino和Eclipse从JavaScript访问外部JAR文件? [英] How to access external JAR files from JavaScript using Rhino and Eclipse?

查看:62
本文介绍了如何使用Rhino和Eclipse从JavaScript访问外部JAR文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mozilla Rhino编写JavaScript服务器应用程序.我想在我的项目中包括HttpClient类,以方便地访问Web,但是我不知道如何配置Eclipse项目以使Rhino加载HttpClient JAR文件.

I'm using Mozilla Rhino to write a JavaScript server application. I would like to include the HttpClient classes in my project to easily access the web, but I can't figure out how to configure my Eclipse project to get Rhino to load the HttpClient JAR file.

我已将 js.jar (来自Rhino)和 httpclient-4.0.1.jar 添加到Eclipse中项目的构建路径中,并且在我的运行配置中,从Rhino的js.jar(它找到了)中指定了Main类,在我的JavaScript文件中,我基本上是这样做的:

I have added js.jar (from Rhino) and httpclient-4.0.1.jar to my project's build path in Eclipse, and in my run configuration I have specified the Main class from Rhino's js.jar (which it finds), and in my JavaScript file I basically do this:

importPackage(org.apache.http.client.methods);
var get = new HttpGet("<some url returning json data>");
get.execute();
print(get.getResponseBodyAsString());

无法这样说:

Exception in thread "Thread-0" org.mozilla.javascript.EcmaError: ReferenceError: "HttpGet" is not defined.

这怎么可能这么难?我一定在做根本上是错误的事情.

How can this be so hard? I must be doing something fundamentally wrong.

推荐答案

好的,问题似乎是我在 httpclient-4.0.1.jar 文件中有多个引用classpath和我项目的构建路径中.除此之外,我似乎还遗漏了 httpclient-4.0.1.jar 所依赖的几个依赖项.清理完我的类路径并将所有必需的jar添加到我的项目后,现在似乎可以按预期找到所有内容.

Okay, the problem seemed to be that I had multiple references of the httpclient-4.0.1.jar file, both in my classpath and in my project's build path. Other than that, I seemed to have left out a couple of dependencies that httpclient-4.0.1.jar depend upon. After cleaning out my classpath and adding all the necessary jars to my project it now seems to find everything as expected.

感谢您的帮助!

这篇关于如何使用Rhino和Eclipse从JavaScript访问外部JAR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆