Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there J2CL binaries without depedency on build system? #58

Closed
jreznot opened this issue Jul 10, 2019 · 16 comments
Closed

Are there J2CL binaries without depedency on build system? #58

jreznot opened this issue Jul 10, 2019 · 16 comments

Comments

@jreznot
Copy link

jreznot commented Jul 10, 2019

Can I just download compiler JAR somewhere and run it with java -jar ?

With old GWT it was a really simple task to start the compiler.

@niloc132
Copy link
Contributor

For just j2cl, if you build it with bazel, there is a jar you can run with just plain java -jar, but that will only transpile individual .java files to .js, it won't produce a single JS executable (as that requires closure as well, or some other analogous way to combine the individual JS files, and ideally optimize them as well). This executable functions much like javac itself, you pass in a classpath and sources, and a few optional flags.

Bazel can also produce a shell script that runs the jar, letting you even skip java -jar itself, and jump straight to running the transpiler.

A maven plugin is under development which lets you take simple maven projects, and combines the various phases of the build (preprocess sources, compile to JS, combine+optimize JS to a single output) into a single, easy to configure step in a pom file.

Whereas GWT2 behaved as a standalone build tool, J2CL is meant to fit into a larger build ecosystem, and not reinvent every wheel, but share as much as possible, and let the build tool decide what needs to be built/rebuilt, etc. On the one hand, this makes it somewhat more difficult to run J2CL itself, but also makes it more flexible, as it is a small gear in a big machine, instead of being the entire machine and assuming a lot about how you will use it.

@jreznot
Copy link
Author

jreznot commented Jul 11, 2019

Bazel can also produce a shell script that runs the jar, letting you even skip java -jar itself, and jump straight to running the transpiler.

Bazel, shell script, JAR, so many things

To be honest, it creates many barriers for adoption. It is so complex and unobvious.

@niloc132
Copy link
Contributor

Right, work is still being done to put the kind of polish on it that GWT2 has. If you use maven, the https://repo.vertispan.com/j2cl/ repository has com.vertispan.j2cl:transpiler, which will bring in all transpiler dependencies including the main class. This is currently packaged for use in the com.vertispan.j2cl:j2cl-maven-plugin, in the same repository - simply put that in a j2cl-compatibile project and build to get executable JS, it picks some sane defaults.

To run the jar you're looking for, try this:

  • run bazel build //transpiler/java/com/google/j2cl/transpiler:*
  • copy the built uberjar out of its build path bazel-bin/transpiler/java/com/google/j2cl/transpiler/J2clCommandLineRunner_deploy.jar
  • run it:
$ java -jar J2clCommandLineRunner_deploy.jar
Error: Argument "<source files>" is required
Usage: j2cl <options> <source files>
use -help for a list of possible options
1 error(s), 0 warning(s).
$ java -jar J2clCommandLineRunner_deploy.jar -help
Usage: j2cl <options> <source files>
where possible options include:
 -classpath (-cp) <path>        : Specifies where to find user class files and
                                  annotation processors.
 -d <path>                      : Directory or zip into which to place compiled
                                  output.
 -help                          : print this message
 -nativesourcepath <path>       : Specifies where to find zip files containing
                                  native.js files for native methods.

@jreznot
Copy link
Author

jreznot commented Jul 11, 2019

Thanks, seems possible to use it like this.
I'm planning to build binaries regularly and put them to some repository, e.g. Bintray.

@gkdn gkdn closed this as completed Sep 11, 2019
@ansorre
Copy link

ansorre commented Oct 1, 2019

Has anyone managed to make it work?
I'm stuck with these errors and nowhere I seem to be able to find the corresponding .natives.js files:

Error: ...Main.java:1: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Error: ...Main.java:1: The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
Error: ...Main.java:22: Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor
Error: ...Main.java:25: String cannot be resolved to a type
etc.....

Any help?

@tbroyer
Copy link
Contributor

tbroyer commented Oct 1, 2019

@Antonio-Sorrentini You need to pass the Java Runtime Emulation library (com.vertispan.j2cl:jre and com.vertispan.j2cl:gwt-internal-annotation, or bazel-bin/jre/java/jre.jar and bazel-bin/external/org_gwtproject_gwt/user/libgwt-javaemul-internal-annotations.jar) in the -classpath in addition to your dependencies.

@ansorre
Copy link

ansorre commented Oct 1, 2019

@tbroyer thank you very much, I was about to give up! :-)

@ansorre
Copy link

ansorre commented Oct 1, 2019

So now the next step is to have closure to work.

java -jar closure-compiler.jar --js="**.js"
./<...>/Main.impl.java.js:3: ERROR - [JSC_MISSING_NAMESPACE_IMPORT] Imported Closure namespace "java.lang.Object$impl" never defined.
const j_l_Object = goog.require('java.lang.Object$impl');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is there any way to do it without bazel or maven and no build tools at all please, just command line?
Is there also a way to use elemental2?

I promise that if I reach my goal I'll write an extensive tutorial on how to do all this. Honestly at the moment it seems impossible to use j2cl if you just want to use it with command line.

@rluble
Copy link
Collaborator

rluble commented Oct 1, 2019

Is there any reason not to use bazel?

Anyway if you can install bazel but still want to be able to build without it you could run bazel build -s <whatever-target-you-want-to-build> and you will see the commands that bazel executes. From that you can see what parameters are passed to J2CL, jscompiler etc, etc. and learn how to build arbitrary targets by hand.

@giavaneerspublicprojects
Copy link

@ansorre
Copy link

ansorre commented Oct 1, 2019

@rluble: thank you very much for the "-s" suggestion, it's really useful. About bazel I can't afford to learn and switch to a new building tool in this moment and after all both j2cl and closure are conceived very well to be just indipendent tools in a complex toolchain, but if the toolchain is fixed and imposed the overall workflow flexibility could severely be affected.

@giavaneerspublicprojects: I'll try my best both in making this work and writing a tutorial about it.

@rluble
Copy link
Collaborator

rluble commented Oct 1, 2019

BTW, which build system are you using? Maybe you could contribute build scripts once you have everything figured out.

@ansorre
Copy link

ansorre commented Oct 1, 2019

@rluble I'm still trying so I can't say anything at the moment. But for now my feelings are that everything can be done and really there is no need for specific scripts or code. What I see totally lacking is documentation, examples, tutorials and the like. In fact even googling for just an example of something real made with j2cl gives nothing at all. Anyway whatever will be, be it code or info, if I succeed I'll do my best to share and give as much as I can. This seems to me a piece of software that deserves a lot more attention and adoption of what is possible at the moment just because of missing info.

@ansorre
Copy link

ansorre commented Oct 1, 2019

Ops, about build system: I use Ubuntu and bazel to build it but then I transfer on another machine and try to integrate the built tools on a windows machine inside my toolchain which is mainly developed by myself. I'm building a very extended and complicated project which is an AI platform I'm going to launch in a few weeks after almost 18 months of development. So far I used JSweet for client side programming, and I like it. But... I feel j2cl would fit better.

@v7r
Copy link

v7r commented Jan 20, 2021

@ansorre

I'll try my best both in making this work and writing a tutorial about it.

Please care to share if you had succeeded.

@ansorre
Copy link

ansorre commented Jan 21, 2021

@ansorre

I'll try my best both in making this work and writing a tutorial about it.

Please care to share if you had succeeded.

Sorry, I didn't succeed and remained with JSweet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants