I'm building a very simple jar with one main method. I've got the Kotlin rules working, and I can build the jar just fine:
kt_jvm_binary(
name = "myapp",
main_class = "MainKt",
srcs = ["src/main/kotlin/Main.kt"]
)
However, that main_class
argument doesn't add anything to the manifest to allow me to run the jar (I assume the one in the bazel-bin folder is the right one).
I've tried using a library then compiling it using the java_binary
rule instead:
kt_jvm_library(
name = "myapp_lib",
srcs = ["src/main/kotlin/Main.kt"]
)
java_binary(
name = "myapp",
main_class = "MainKt",
visibility = ["//visibility:public"],
runtime_deps = [":myapp_lib"],
deploy_manifest_lines = ["Main-Class: MainKt"]
)
Now I have two jars; myapp.jar which just has a manifest, and myapp_lib.jar which has the class file. Neither of them have a main class in the manifest, regardless of whether I include that deploy_manifest_lines
argument or not.
How do I build my very simple jar with a main class that allows me to run it?
(Note that I will be working with desktops and TornadoFX, not Android.)
A lot of things in Bazel aren't "magical", and this is an example. The "main_class" isn't there to affect packaging, it's there to tell the bazel *_binary rule how to execute, so you can do bazel run //path/to/my/binary:target
. It doesn't affect packaging. That's up to you. You would add your own meta-inf information and make sure the resources=
pulls in your packaging metadata.
Part of this is because Bazel doesn't (by default) make an "executable jar" but instead builds a wrapper script which you execute which invokes the jvm with the jar.
Your second example should work... you're not looking at the right jar. The jar that actually has all the deployment bits should be: myapp_deploy.jar
which contains all the "upstream" deps' classes, plus any meta-inf stuff, all baked into a single jar.