20

Is there any JavaScript jvm implementations?
If no, can you give me some reasons why it hasn't realized already? (not possible probably?) I'm trying to understand what is absent to create one?

Reason why i'm asking is that i want to create web browser ide with compile functionality without even having jdk or jre installed on the computer(just in browser).

  • I have little experience in Java, but still.. Think about it, your JVM wont be able to access disk, OS, or make random network connections, because of the various limitations the browser puts.. HTH – UltraInstinct Sep 07 '12 at 11:00
  • *"web browser ide with compile functionality"* It would pay to mention the goal 1st up in future, to clear some confusion. ;) – Andrew Thompson Sep 07 '12 at 11:01
  • It would be infinitely easier to just send the Java-code to the server and compile it there. – pap Sep 07 '12 at 11:16
  • 1
    @pap Preventing Denial of Service attacks on the server for code compilation cannot be 'infinitely easier'. ;) – Andrew Thompson Sep 07 '12 at 11:19
  • @AndrewThompson - let's make a race. You start implementing a JVM in JavaScript and I'll get cracking on DOS-proofing a low-profile website. Let's see who finishes first ;) – pap Sep 07 '12 at 11:22
  • Anyone that would run Java Applets (ie. java for web browsers)? – LatinSuD Mar 18 '20 at 13:25

7 Answers7

18

Most current one seems to be Doppio

Sanjay T. Sharma
  • 22,857
  • 4
  • 59
  • 71
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
7

You may have a look at the bck2brwsr (aka java.net HTML)

  • it is a VM that transforms java byte code into JavaScript (Bck2Brwsr Virtual Machine)
  • provides a Java based wrapper to HTML (HTML via Java APIs)

The scope of the project is not to execute any existing java library. (see http://wiki.apidesign.org/wiki/Bck2Brwsr)

There are two nice examples on the web:

  • a calculator, that gives good technical insight (http://xelfi.cz/bck2brwsr/)
  • a nice space invader demo as a proof of concept (JAYDAY 2013 java summit page)

To get started with a working example (needs Maven and JDK7):

Step 1: load archetype

mvn archetype:generate -DarchetypeGroupId=org.apidesign.bck2brwsr \
 -DarchetypeArtifactId=bck2brwsr-archetype-html-sample -DarchetypeVersion=0.7.2 \
 -DarchetypeRepository=https://maven.java.net/content/repositories/releases/

Step 2: build HTML page and dependencies and pack as ZIP file

mvn install
# produces bck-1.0-SNAPSHOT-bck2brwsr.zip

Step 3: unpack ZIP

cd target; unzip bck-1.0-SNAPSHOT-bck2brwsr.zip
  creating: public_html/
  creating: public_html/lib/
  extracting: public_html/lib/emul-0.7.2-rt.jar  
  extracting: public_html/lib/javaquery.api-0.7.2.jar  
  inflating: public_html/bck2brwsr.js  
  extracting: public_html/bck-1.0-SNAPSHOT.jar  
  inflating: public_html/index.html 

Step 4: open index.html with your browser

Steve Oh
  • 1,149
  • 10
  • 18
6

Not sure how mature jsJVM is but looks like something which you would be interested in. As the page says, it's JVM written in Javascript.

Sanjay T. Sharma
  • 22,857
  • 4
  • 59
  • 71
3
  1. +script seems to be interesting, too and the author also works on an web based IDE.

  2. BicaVM may be another option.

  3. The Orto project may be dead.

Community
  • 1
  • 1
user573215
  • 4,679
  • 5
  • 22
  • 25
1

Very late answer, but for future inquirers: There is a new Java JVM implementation for JavaScript that has been released since this question was first asked. It claims to implement a JVM even without Java installed.

https://www.javapoly.com/

KWallace
  • 1,570
  • 1
  • 15
  • 25
  • A link to a potential solution is always welcome, but please [add context around the link](//meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being _barely more than a link to an external site_ is a possible reason as to [Why and how are some answers deleted?](//stackoverflow.com/help/deleted-answers). – Mogsdad May 10 '16 at 02:13
  • 2
    Is that better? And can someone explain why my answer was downvoted and deleted, whereas the Doppio answer above was upvoted 12 times and provided no more useful information than my answer? – KWallace May 16 '16 at 19:27
  • Has this JVM implementation a GUI API? – Horcrux7 Mar 17 '18 at 11:42
  • Unfortunately looks dead – Paul Heil Apr 23 '22 at 02:35
0

One of the problems of compiling Java using JavaScript is that the compiler typically needs to know the existence (or not) of the methods and attributes of a target Java minimum version. To even know that information, you would need to store properties, or variables that describe the public members of every single of class of the target J2SE. That represents a very big chunk of information.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Can't you put that staff in coockie or html5 Local Storage ? – Nikolas Papirniy Sep 07 '12 at 11:11
  • I doubt the '5 meg' of expected space in local storage would be enough to hold textual representations of those public and (I forgot) protected members of non-final classes for a JRE of the vintage of 1.6 or 1.7. Maybe 1.1 & 1.2. – Andrew Thompson Sep 07 '12 at 11:17
0

There is an JVM written in Java which has an JavaScript Bytecode Interpreter: https://gitlab.com/neoexpert/jvm

It can also compile Bytecode directly to JavaScript to improve performance.

neoexpert
  • 465
  • 1
  • 10
  • 20