有没有用 javascript 实现的 Java 字节码阅读器?
我知道有很多库可以读取用 Java 编写的字节码。有人知道用 Javascript 实现的字节码库吗?
I know there are lots of libraries that read byte codes that are written in Java. Does someone know of a byte code library that is implemented in Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 javascript 通常在浏览器内运行,因此它通常无法从文件中读取实际字节,这使得它不太适合读取 java 字节。如果您以某种方式将字节码编码为 javascript 可以读取的形式,那么您希望库用它做什么?您能否提供有关您正在尝试做什么的更多详细信息?
如果您希望能够用 Java 编写代码并使其在浏览器中运行,请查看 GWT。它使用 Java 将字节码重新编译为优化的 JavaScript。
编辑
根据您添加的评论,您希望“找出本地磁盘上的 jar 文件中使用的类和方法”:
由于 javascript 无法访问本地磁盘上的文件(位于至少,在不使用 ActiveX 的情况下),该技术根本不允许发生此类事情。您想使用 javascript 而不是 java 来实现此目的是否有原因?
如果听起来我在质疑你的动机,请接受我的道歉。我真的只是想获得足够的信息来充分回答你的问题。
Since javascript is typically run inside a browser, it generally cannot read the actual bytes out of files, which makes it less-than-ideal for reading java bytes. If you somehow got the byte codes encoded in a form that the javascript could read, what would you expect the library to do with it? Can you provide more details about what you're trying to do?
If you're looking to be able to write code in Java, and have it run inside a browser, take a look at GWT. It uses Java to recompile your byte-code into optimized javascript.
Edit
Based on your added comment, that you are hoping to "find out the classes and methods used in a jar file on my local disk":
Since javascript is unable to access files on a local disk (at least, without using ActiveX), the technology simply won't allow for this sort of thing. Is there a reason you wanted to use javascript for this, rather than java?
And please accept my apologies if it sounded like I was questioning your motives. I really just wanted to get enough information to be able to adequately answer your question.
更新:
看起来我试图链接到下面的日本项目早已不存在了。
无论如何,时间已经过去了,现在 Google 上出现了一些“jvm in javascript”的点击率。即:
看看我发现了什么:
http://ejohn.org/blog/running-java-in-javascript/
这有帮助吗?
编辑:不幸的是,原始项目的网站似乎已经死了。
您可以尝试访问网络档案,此处< /a>(日语,尝试用 Google 翻译它,但我猜这太间接了:))
看在上帝的份上,如果您点击该链接,请通过防病毒软件运行您的下载。
不知道是否值得信赖。
Update:
It looks like the Japanese project I tried to link to below is long gone.
In any case, time has passed and now there are a couple of hits for "jvm in javascript" on Google. Namely:
Look what I found:
http://ejohn.org/blog/running-java-in-javascript/
Does this help?
Edit: unfortunately it looks like the original project's site is dead.
You could try through the Web Archive, here (in Japanese, tried to Google translate it, but I guess it was too much indirection :))
For goodness sake, if you follow that link, run your download through an anti-virus.
I don't know if it's trustworhty.
有一些编译器可以将 Java 编译为 JavaScript。作为最后的手段,您可以使用其中一个编译器来获取用 Java 编写的 JVML 字节码反汇编器,并将其编译为 JavaScript。此类编译器的一个示例是 GWT。
同样,也有一些编译器可以将 JVML 字节码编译为 JavaScript。同样,您可以采用上述用 Java 编写的 JVML 字节码反汇编器之一,使用任何 Java 到 JVML 编译器(
javac
、ecj
、gcj
, ...) 将其编译为 JVML(即.class
文件),然后将这些.class
文件编译为 JavaScript。There are compilers which can compile Java to JavaScript. As a last resort, you can use one of those compilers to take a JVML bytecode disassembler written in Java and compile it to JavaScript. One example of such a compiler is GWT.
Similarly, there are compilers which can compile JVML bytecode to JavaScript. Again, you can take one of the above JVML bytecode disassemblers written in Java, use any Java-to-JVML compiler (
javac
,ecj
,gcj
, …) to compile it to JVML (i.e..class
files), then compile those.class
files to JavaScript.