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?
-
2What do you want to do with it? Read the byte codes and dump them out? Analyze them? – Pointy Dec 15 '10 at 21:40
-
1find out the classes and methods used in a jar file on my local disk... – vkraemer Dec 15 '10 at 22:55
-
1+1 for asking a perfectly valid question that no one seems to be able to deal with without questioning your motives. – Mark Bolusmjak Dec 15 '10 at 23:06
-
1There's difference between questioning motives and questioning intentions ("what do you want to do?" vs "why do you want to do it?") – Zecc Dec 16 '10 at 00:26
-
motive: extend something like jarfinder.com, findjar.com and others to quickly answer a query like this one: http://stackoverflow.com/questions/4417820/how-to-list-dependencies-of-a-jar. Shipping the whole jar to the site for analysis seems wasteful. It seems bogus that javascript cannot perform the task that a simple html input type="file" executes all around the web, daily. – vkraemer Dec 16 '10 at 01:26
-
Yeah, it would be nice if browsers allowed javascript to actually read contents of files selected via HTML input. Unfortunately, they don't. I don't even think ActiveX lets you read binary files. – StriplingWarrior Dec 16 '10 at 21:35
3 Answers
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.

- 151,543
- 27
- 246
- 315
-
Would the downvoter care to explain their objection to this answer? – StriplingWarrior Dec 15 '10 at 23:41
-
I wasn't the one who downvoted, but I'd just like to say that it's perfectly possible to run JavaScript outside the context of a browser, and have access to files on a disk. – Zecc Dec 16 '10 at 00:25
-
I downvoted because what you had entered at the time was not an anwser to the very clear question the op had posted. Your questions belong in the comments section. Your statement about javascript belonging in browsers is dated and misleading. Javascript needs no browser (see v8, node.js, rhino, etc). I may have let it go but you have 5000+ points and I expected more from a member of your caliber. – Mark Bolusmjak Dec 16 '10 at 20:23
-
@z5h: Thank you for explaining. I don't mind down-votes as long as they are explained so I can learn from them. Even "a member of my caliber" doesn't know everything. In this case, though, I don't feel that I was wrong. Javascript is *typically* run inside a browser, so unless the OP was planning to use a special framework like those you mention, what he's asking for isn't possible. In cases like this, I often suggest workarounds. If he was trying to read specific bytecode so that he could evaluate/run it, then GWT might be an appropriate workaround. – StriplingWarrior Dec 16 '10 at 21:21
-
@z5h: If not, I would need more info to better answer the question, so I asked for more details. Even Jon Skeet does this sort of thing in his answers (http://stackoverflow.com/questions/4465242/4465266#4465266). As it turns out, he isn't trying to run the bytecode, but he *is* trying to inspect it from within a browser, so the appropriate answer is "it cannot be done using javascript alone." – StriplingWarrior Dec 16 '10 at 21:21
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.

- 4,220
- 19
- 17
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.

- 1
- 1

- 363,080
- 75
- 446
- 653