Skip to content
Generates Java annotated with JsInterop from JavaScript extern sources
Java Python JavaScript Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build_defs
internal_do_not_use
java/jsinterop/generator
javatests/jsinterop/generator Mark native JsType interface with @FunctionalInterface. Oct 23, 2019
maven
third_party
.bazelversion
.gitignore
.travis.yml
BUILD
CONTRIBUTING.md
LICENSE
README.md
WORKSPACE
bazel_build_test.sh
jsinterop_generator.bzl
jsinterop_generator_import.bzl
release_jsinterop_generator.sh

README.md

JsInterop Generator · Build Status

The jsinterop generator is a java program that takes closure extern files as input and generates Java classes annotated with JsInterop annotations.

This project is used for building Elemental2. Any other uses are experimental. You can use it to generate java APIs for other javascript libraries but we don't provide any official support. Feel free to open issues on the github issue tracker, though.

Run with Bazel

If your project use Bazel. You can use the skylark rule jsinterop_generator to generate java code.

You need to add this repository as an external dependency in your WORKSPACE file

new_http_archive(
  name = "com_google_jsinterop_generator",
  url="https://github.com/google/jsinterop-generator/archive/master.zip",
  strip_prefix="jsinterop-generator-master",
)

and then define a jsinterop_generator target in your 'BUILD' file

load("@com_google_jsinterop_generator//:jsinterop_generator.bzl", "jsinterop_generator")

jsinterop_generator(
    name = "my_thirdparty_lib",
    srcs = ["my_externs.js"],
)

You can now directly depend on :my_thirdparty_lib target in your java_library rules or build the jar files with bazel build //path/to/your/BUILD/file/directory:my_thirdparty_lib. The jar files with the generated source will created in bazel-bin/path/to/your/BUILD/file/directory.

Run as a standalone java program

Build the generator from source

  • You need to install Bazel.

  • clone this repository with git: git clone https://github.com/google/jsinterop-generator.git

  • Inside the repository, have bazel build the jar file:

    $ bazel build //java/jsinterop/generator/closure:ClosureJsinteropGenerator_deploy.jar
    
  • The generated jar file can be found at bazel-bin/java/jsinterop/generator/closure/ClosureJsinteropGenerator_deploy.jar

Or download the generator

TODO(dramaix): provides link to download the generator.

Run the generator

Now you have the jar file, just invoke

java -jar /path/to/ClosureJsinteropGenerator_deploy.jar [options] externs_file...

List of required options :

Option Meaning
--output file Path to the jar file that will contain the generated java classes
--output_dependency_file file Path to the dependency file generated by the generator.
--package_prefix string Prefix used when we build the java package
--extension_type_prefix string Value used for prefixing extension types. It's a good practice to pass the name of the library in upper camel case.

Contributing

Please refer to the contributing document.

Licensing

Please refer to the license file.

Disclaimer

This is not an official Google product.

You can’t perform that action at this time.