Comments (16)
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.
@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.
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.
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.
@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.
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.
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.
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.
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.
@tbroyer thank you very much, I was about to give up! :-)
from j2cl.
from j2cl.
BTW, which build system are you using? Maybe you could contribute build scripts once you have everything figured out.
from j2cl.
@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.
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.
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.
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)
- package listing?
- io_bazel_rules_kotlin_configured HOT 4
- How to fix the error: unused native file on Windows 11? HOT 1
- Ready to work on download file
- Wasm sample broken v2 HOT 2
- JUnit test example for wasm HOT 5
- I receive the following issue during the build. Have anyone an idea what the reason is: HOT 3
- [WASM] HashMap.computeIfAbsent doesn't work as expected HOT 1
- Can't run j2cl on Bazel 6 HOT 6
- Bazel: accidental impossible target HOT 2
- goog.reflect.sinkValue and deadcode elimination
- How to use it in vite +vue3
- Automate release/tag of the repo on green builds
- predicate is not usable by but exposed to JavaScript. HOT 3
- Support `rules_jvm_external` or `j2cl_maven_import_external` private registry HOT 1
- JRE emulation misses java.io.Externalizable
- Add dependabot to keep GitHub Actions up-to-date
- public methods are too eagerly optimized away; need ability to declare "@export" annotation HOT 9
- "Native JsType method '...' should be native, abstract or JsOverlay." error prevents default implementation for vanilla Java HOT 3
- `closure_js_library` typecheck fails when depending on j2cl jre HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from j2cl.