Giter Site home page Giter Site logo

Comments (16)

niloc132 avatar niloc132 commented on May 18, 2024 2

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.

from j2cl.

tbroyer avatar tbroyer commented on May 18, 2024 2

@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.

from j2cl.

rluble avatar rluble commented on May 18, 2024 2

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.

from j2cl.

ansorre avatar ansorre commented on May 18, 2024 1

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.

from j2cl.

ansorre avatar ansorre commented on May 18, 2024 1

@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.

from j2cl.

niloc132 avatar niloc132 commented on May 18, 2024

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.

from j2cl.

jreznot avatar jreznot commented on May 18, 2024

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.

from j2cl.

jreznot avatar jreznot commented on May 18, 2024

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

from j2cl.

ansorre avatar ansorre commented on May 18, 2024

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?

from j2cl.

ansorre avatar ansorre commented on May 18, 2024

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

from j2cl.

giavaneerspublicprojects avatar giavaneerspublicprojects commented on May 18, 2024

from j2cl.

rluble avatar rluble commented on May 18, 2024

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

from j2cl.

ansorre avatar ansorre commented on May 18, 2024

@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.

from j2cl.

ansorre avatar ansorre commented on May 18, 2024

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.

from j2cl.

v7r avatar v7r commented on May 18, 2024

@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.

from j2cl.

ansorre avatar ansorre commented on May 18, 2024

@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.

from j2cl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.