{"id":15069813,"url":"https://github.com/jtulach/bck2brwsr","last_synced_at":"2025-04-12T21:28:36.933Z","repository":{"id":29262007,"uuid":"32794630","full_name":"jtulach/bck2brwsr","owner":"jtulach","description":"Bck2Brwsr VM to transpile Java bytecode to JavaScript","archived":false,"fork":false,"pushed_at":"2025-03-16T09:20:03.000Z","size":19909,"stargazers_count":118,"open_issues_count":9,"forks_count":15,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-04T01:09:40.037Z","etag":null,"topics":["bytecode","gradle-plugins","java","javascript","jvm","maven-plugin","transpiler"],"latest_commit_sha":null,"homepage":"http://bck2brwsr.apidesign.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jtulach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-24T11:32:34.000Z","updated_at":"2025-03-24T13:38:57.000Z","dependencies_parsed_at":"2022-07-12T05:18:30.617Z","dependency_job_id":"caa7fada-8b72-40e5-9940-11a0dff20b18","html_url":"https://github.com/jtulach/bck2brwsr","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtulach%2Fbck2brwsr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtulach%2Fbck2brwsr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtulach%2Fbck2brwsr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtulach%2Fbck2brwsr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jtulach","download_url":"https://codeload.github.com/jtulach/bck2brwsr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248634000,"owners_count":21136961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","gradle-plugins","java","javascript","jvm","maven-plugin","transpiler"],"created_at":"2024-09-25T01:44:49.781Z","updated_at":"2025-04-12T21:28:36.907Z","avatar_url":"https://github.com/jtulach.png","language":"Java","funding_links":[],"categories":["JVM实现"],"sub_categories":[],"readme":"[![Build Status](http://hudson.apidesign.org/hudson/job/bck2brwsr/badge/icon)](http://hudson.apidesign.org/hudson/job/bck2brwsr/badge/icon)\n\n\n# Bring Java Back to Browser!\n\n[Bck2Brwsr](http://bck2brwsr.apidesign.org) VM is a Java virtual machine which is capable to take bytecode \nand transpile it\n(either ahead-of-time - e.g. during compilation on desktop - or just-in-time, e.g. in a browser) \ninto appropriate JavaScript code which does the same thing. As a result one can write in Java, \ncompile with JavaC, run it with [Bck2Brwsr](http://bck2brwsr.apidesign.org) in any modern browser. \n\n# Getting Started\n\nIf you have a **Maven** or **Gradle** project it is as easy as adding one plugin\nto get your Java application into browser. Imagine you have a simple hello world\napplication in `src/main/java` structure of your project:\n```java\npublic class Hello {\n    public static void main(String... args) {\n        System.err.println(\"Hello from Java in JS!\");\n    }\n}\n```\nthen it is just about adding following plugin into your `pom.xml`:\n```xml\n    \u003cbuild\u003e\n        \u003cplugins\u003e\n            \u003cplugin\u003e\n                \u003cgroupId\u003eorg.apidesign.bck2brwsr\u003c/groupId\u003e\n                \u003cartifactId\u003ebck2brwsr-maven-plugin\u003c/artifactId\u003e\n                \u003cversion\u003e0.51\u003c/version\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n```\nand executing `mvn clean install bck2brwsr:aot bck2brwsr:show` -\nmore info in a [dedicated page](docs/MAVEN.md).\n\nIt is similarly easy with **Gradle**. Just by adding (the same)\nsingle plugin and configuring your script to use it:\n```groovy\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n    dependencies {\n        classpath \"org.apidesign.bck2brwsr:bck2brwsr-maven-plugin:0.51\"\n    }\n}\n\nrepositories {\n    mavenCentral()\n}\n\napply plugin: 'bck2brwsr'\n```\nyou'll be able to invoke `./gradlew bck2brwsrShow` and see your Java \napplication greetings from the browser. \nAn in-depth [tutorial is available](docs/GRADLE.md) as well.\n\n## How do I deploy?\n\nJust copy the generated files to any web hosting service! No application\nserver needed, no code needs to be executed on the server. The whole application is \n*just* a set of pages that can be copied anywhere. In case of **Gradle** it consists of:\n```bash\n$ find build/web/\nbuild/web/\nbuild/web/index.html\nbuild/web/lib\nbuild/web/lib/emul-0.51-rt.js\nbuild/web/main.js\nbuild/web/bck2brwsr.js\n```\nThe structure of pages generated by **Maven** is similar with the primary HTML file being `target/index.html`.\n\n## Talking to Your Java Code\n\nOnce your application is running in the browser, you can interact with it\nfrom a console. Btw. output of `System.out` and `System.err` is primarily \nprinted into the console. Open the console and try:\n```js\nvar System = vm.loadClass(\"java.lang.System\")\nSystem.exit(0)\n```\nand voilá! your browser is closed. Obviously the above snippet is more useful for \nother methods in your application than `System.exit`. You can use it to \nlocate any `public class` and invoke any of its `public static` methods.\n\n## Launching\n\nBrowsers download scripts asynchronously, as such the `vm.loadClass` may not be\nimmediatelly ready, but it may get loaded with a delay. To accomodate such restriction\none can use a callback style of the above:\n```js\nvm.loadClass(\"java.lang.System\", function(System) {\n  System.exit(0)\n});\n```\nUsage of callback is recommended when executing the first Java method (as that usually means\nloading of new scripts) and is exactly what the default content of `index.html` does:\n```html\n\u003cscript src='bck2brwsr.js'\u003e\u003c/script\u003e\n\u003cscript\u003e\nvar vm = bck2brwsr('main.js');\nvm.loadClass('Hello', function(mainClass) {\n  mainClass.invoke('main');\n});\n\u003c/script\u003e\n```\nThe first line loads the [Bck2Brwsr](http://bck2brwsr.apidesign.org) virtual machine. \nThen one fills it with transpiled code of one's application `var vm = bck2brwsr('main.js');`\ntogether with required libraries. At the end one invokes `main` method of the `Hello` class\nusing the callback syntax.\n\n# More?\n\nMore info at [project home page](http://bck2brwsr.apidesign.org). Questions to [bck2brwsr group](https://groups.google.com/forum/#!forum/bck2brwsr).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtulach%2Fbck2brwsr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjtulach%2Fbck2brwsr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtulach%2Fbck2brwsr/lists"}