{"id":16651617,"url":"https://github.com/bsorrentino/java2typescript","last_synced_at":"2025-03-21T16:31:30.411Z","repository":{"id":37686772,"uuid":"115617066","full_name":"bsorrentino/java2typescript","owner":"bsorrentino","description":"Java Processor to generate Typescript Definition from Java classes - This is to help developing on JVM javascript engine (ie Nashorn) using Typescript ","archived":false,"fork":false,"pushed_at":"2024-10-09T19:36:21.000Z","size":1939,"stargazers_count":47,"open_issues_count":9,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T03:07:08.850Z","etag":null,"topics":["java","java-processor","javascript","jvm","nashorn","typescript"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsorrentino.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2017-12-28T11:32:18.000Z","updated_at":"2025-03-04T08:56:24.000Z","dependencies_parsed_at":"2024-10-28T11:39:07.683Z","dependency_job_id":null,"html_url":"https://github.com/bsorrentino/java2typescript","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsorrentino%2Fjava2typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsorrentino%2Fjava2typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsorrentino%2Fjava2typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsorrentino%2Fjava2typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsorrentino","download_url":"https://codeload.github.com/bsorrentino/java2typescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244829507,"owners_count":20517313,"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":["java","java-processor","javascript","jvm","nashorn","typescript"],"created_at":"2024-10-12T09:25:54.339Z","updated_at":"2025-03-21T16:31:30.014Z","avatar_url":"https://github.com/bsorrentino.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22java2ts-processor%22\"\u003e\u003cimg src=\"https://img.shields.io/maven-central/v/org.bsc.processor/java2ts-processor.svg\"\u003e\n\n\n# java2typescript\n\n[![Join the chat at https://gitter.im/bsorrentino/java2typescript](https://badges.gitter.im/bsorrentino/java2typescript.svg)](https://gitter.im/bsorrentino/java2typescript?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nJava Processor to **generate [Typescript](https://www.typescriptlang.org/)  Definition file (`.d.ts`)** from whatever Java classes.\n\n## Diagram of solution\n\n```mermaid\n---\ntitle: Java to TypeScript Conversion Process\n---\nflowchart LR\n\n    subgraph \"Java Compiler\"\n        B(Java2TypeScript Processor) \n    end\n   \n    subgraph \"Java Project\"\n        direction LR\n        A[Package_Info.java]:::javaSrc ---|Lookup annotations| B\n        C[Dependencies Classpath]:::javaSrc ---|Lookup classes| B\n    end\n\n    subgraph \"Typescript\"\n        D[\u0026lt;Output\u003e.d.ts]:::tsFile\n        E[\u0026lt;Output\u003e_types.ts]:::tsFile\n    end\n    \n    B o--\u003e|Generate| D\n    B o--\u003e|Generate| E\n    \n```\n\n## What is it for ?\n\nThis is to help developing on **JVM javascript engine**, either [GraalJs](https://github.com/graalvm/graaljs) or [Rhino](https://github.com/mozilla/rhino) using [Typescript](https://www.typescriptlang.org/)\n\u003e [Nashorn](http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html) has been **DEPRECATED** (refer to [JEP335](http://openjdk.java.net/jeps/335) )\n\nThe main goal is having the definitions available in the modern IDE like [Visual Studio Code](https://code.visualstudio.com/) and [Atom](https://atom.io/) and then use the **intellisense** feature available for java classes within typescript\n\n## What is it not for ?\n\nIt is not a transpiler from Java to Javascript like  [datathings/java2typescript](https://github.com/datathings/java2typescript)\n\n## Similar projects\n\n* [typescript-generator](https://github.com/vojtechhabarta/typescript-generator)\n\u003e typescript-generator is a tool for generating TypeScript definition files (.d.ts) from Java JSON classes. If you have REST service written in Java using object to JSON mapping you can use typescript-generator to generate TypeScript interfaces from Java classes.\n* [1c](https://1c.wizawu.com/#/whatis)\n\u003e 1c is aimed to compile TypeScript to runnable code on both JVM and web browser. You can implement the full stack with TypeScript while using libraries from Maven and NPM together.\n\n## Modules Support\n\n* Rhino is compliant with CommonJS module loader for the JVM\n\u003e Graaljs is compliant with ES6 module loader for the JVM\n\n## DEMO\n\nTo give an idea about **how to work** there is a demo available online [here](https://java2ts-demo.herokuapp.com/).\n\n\u003e The backend of such demo has been developed using typescript on jvm provided by this project itself ([dogfooding](https://en.wikipedia.org/wiki/Eating_your_own_dog_food)).\n\u003e [java2typescript-demo project](https://github.com/bsorrentino/java2typescript-demo)\n\n## Description\n\nBasic idea is to develop a Project by mixing Java \u0026 Javascript code (or completely in Javascript) relying on the [Nashorn Javascript engine](http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html) or [Rhino javascript engine](https://github.com/mozilla/rhino). This powerful engines enable Javascript language in JVM and they allow to access to every java class present in classpath in a pretty straightforward way.\nThat's cool, the Javascript is very easy to learn, but the question are :\n 1. _Is it possible develop a complete and well structured Javascript application ?_\n 1. _Developing in Javascript on JVM is as productive as programming in Java ?_\n\nJust to answer the questions above that this project has been developed.\n\n\u003e 1. _Is it possible develop a complete and well structured Javascript application ?_\n\u003e\u003e **Yes it is, but with help of a powerful [Typescript](https://www.typescriptlang.org/) that fills language's gaps and produce Javascript as output**  \n\u003e\n\u003e 1. _Developing in Javascript on JVM is as productive as programming in Java ?_\n\u003e\u003e **Yes it could be, but we need :**\n\u003e\u003e * An IDE with intellisense capability that is able to inspect java/javascript classes during development.\n\u003e\u003e\u003e **This is the main goal of project, that is to generate Typescript Declarations enabling every Typescript-Aware IDE (eg. [Atom](https://ide.atom.io/), [VSCode](https://code.visualstudio.com/)) to give you the __intellisense__ feature make more comfortable use access to Java features/classes from Javascript**\n\u003e\u003e\n\u003e\u003e * A module module system that allow to arrange application in separate well-defined modules\n\u003e\u003e\u003e **This is achieved by project [jvm-npm](https://github.com/bsorrentino/jvm-npm) that enable use of [commonJS](https://en.wikipedia.org/wiki/CommonJS) enabling [Typescript Modules](https://www.typescriptlang.org/docs/handbook/modules.html).**\n\u003e\n\n## Getting Started\n\nLet assume that you have successfully setup a java project\n\n### Declares the classes you want to generate the Typescript declaration for\n\nCreate a file `package-info.java` and annotate the given package with `@Java2TS` that will contain all the `@Type` of which you want the Typescript declaration.\n\n** Type Attributes **\n\nName | Mandatory | Type | Description\n--- | --- | --- | ---\n**value** | Yes | Class | Full Qualified Name of Java class\n**alias** | No | String | Assign a new name to exported class in typescript\n**export** | No | boolean | If **true**, other than typescript declaration adds definition in file *`-types.ts`. **It is need for instantiable classes, in order  to use `new` operator or factory method(s)**\n**functional** | No | boolean | If **true** other than typescript declaration adds a **particular** definition. Valid only for interfaces that have one abstract method and haven't `@FunctionalInterface` annotation\n\n**Example**\n```Java\n@Java2TS(declare = {\n\n  @Type(java.nio.file.Files.class, export=\"true\"),\n  @Type(java.nio.file.Path.class),\n  @Type(java.nio.file.Paths.class, export=\"true\"),\n\n  @Type(value=java.util.stream.Stream.class,export=true),\n\n  @Type(java.util.Collection.class),\n  @Type(java.util.Map.class),\n  @Type(value=java.util.List.class, alias=\"List\" ),\n  @Type(java.util.Set.class),\n  @Type(value=java.util.Arrays.class, export=true),\n\n  @Type(java.util.Optional.class),\n\n  @Type(value=java.net.URI.class, export=true),\n  @Type(java.net.URL.class),\n\n  @Type(java.lang.Runnable.class, functional=true)\n\n})\npackage org.mypackage;\n```\n\n### Add the dependency containing the Java2TS Processor\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.bsc.processor\u003c/groupId\u003e\n  \u003cartifactId\u003ejava2ts-processor\u003c/artifactId\u003e\n  \u003cversion\u003eversion\u003c/version\u003e\n\u003c/dependency\u003e\n\n```\n### Add the Annotation Processor Plugin\n\n**Graajs compatibility [see samples](./samples)**\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003eorg.bsc.maven\u003c/groupId\u003e\n  \u003cartifactId\u003emaven-processor-plugin\u003c/artifactId\u003e\n  \u003cversion\u003e5.1\u003c/version\u003e\n  \u003cexecutions\u003e\n    \u003cexecution\u003e\n      \u003cid\u003eprocess\u003c/id\u003e\n      \u003cgoals\u003e\n        \u003cgoal\u003eprocess\u003c/goal\u003e\n      \u003c/goals\u003e\n      \u003cphase\u003egenerate-sources\u003c/phase\u003e\n      \u003cconfiguration\u003e\n          \u003coutputDirectory\u003e${project.build.directory}\u003c/outputDirectory\u003e\n       \u003coptions\u003e\n            \u003cts.outfile\u003ename\u003c/ts.outfile\u003e\u003c!-- name of generated file --\u003e\n       \u003c/options\u003e\n      \u003c/configuration\u003e\n    \u003c/execution\u003e\n  \u003c/executions\u003e\n\u003c/plugin\u003e\n\n```\n\n**Enforce [Rhino](https://github.com/mozilla/rhino) compatibility [see samples](./samples.rhino)**\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003eorg.bsc.maven\u003c/groupId\u003e\n  \u003cartifactId\u003emaven-processor-plugin\u003c/artifactId\u003e\n  \u003cversion\u003e5.1\u003c/version\u003e\n  \u003cexecutions\u003e\n    \u003cexecution\u003e\n      \u003cid\u003eprocess\u003c/id\u003e\n      \u003cgoals\u003e\n        \u003cgoal\u003eprocess\u003c/goal\u003e\n      \u003c/goals\u003e\n      \u003cphase\u003egenerate-sources\u003c/phase\u003e\n      \u003cconfiguration\u003e\n          \u003coutputDirectory\u003e${project.build.directory}\u003c/outputDirectory\u003e\n       \u003coptions\u003e\n            \u003cts.outfile\u003ename\u003c/ts.outfile\u003e\u003c!-- name of generated file --\u003e\n            \u003ccompatibility\u003erhino\u003c/compatibility\u003e\n       \u003c/options\u003e\n      \u003c/configuration\u003e\n    \u003c/execution\u003e\n  \u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\n\n### Use Maven Archetype\n\nThe easier way to start your **Typescript on JVM** project is using the provided maven archetype\n\n**Interactive Mode**\n\n\u003e```\n\u003emvn archetype:generate \\\n\u003e-DarchetypeGroupId=org.bsc.processor \\\n\u003e-DarchetypeArtifactId=java2ts-processor-archetype \\\n\u003e-DarchetypeVersion=1.1.0\n\u003e```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsorrentino%2Fjava2typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsorrentino%2Fjava2typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsorrentino%2Fjava2typescript/lists"}