Fork me on GitHub
#babashka
<
2020-08-16
>
borkdude16:08:02

Example of how to create a regular uberjar for a babashka project: https://github.com/borkdude/babashka/issues/535#issuecomment-674518153

borkdude16:08:25

There was someone here mentioning a problem with --uberscript and the order of namespaces being off. That should be fixed now on master.

borkdude18:08:33

$ clojure -A:depstar -m hf.depstar.uberjar MyProject.jar -m proj
Building uber jar: MyProject.jar
Processing pom.xml for {proj/proj {:mvn/version "0.1.0"}}
$ bb -jar MyProject.jar
:foo - failed: int?

nate19:08:43

This is awesome.

borkdude19:08:15

I was discussing a possible deprecation of --uberscript in favor of better support for uberjars, but maybe both have their place

nate19:08:15

I think uberscript still has a place. Nice for scripts with some small deps to set as executable and go.

nate19:08:01

To get the same with bb -jar app.jar you have to make a wrapper script or alias.

borkdude19:08:39

I guess so yeah, because you can't just ./app.jar and make the OS execute bb can you?

borkdude19:08:55

but on Windows that doesn't work altogether so bb -jar app.jar would then be cross platform

nate19:08:01

That would be nifty

borkdude19:08:04

I'm currently investigating if I can compile depstar to create an uberjar with bb itself...

borkdude19:08:25

bb -cp $(clojure -Spath -A:babashka) --uberjar foo.jar -m my.main

nate19:08:04

Oh! Make bb capable of uberjarring on its own.

nate19:08:57

Oh wow, hadn't thought of that.

borkdude19:08:21

although not strictly needed, it would be nice

nate19:08:17

Indeed.

borkdude19:08:19

It seems to work :)

nate19:08:00

A pleasant development.

borkdude19:08:22

One caveat: more memory usage and bigger binary but same issue as I had with including datafy: probably some part of clojure is touched, that pulls in a whole lot. Maybe it's the Clojure compiler itself, since depstar can do AOT

borkdude19:08:08

Yep, that was it :-D

nate19:08:45

Ah, wow again.

borkdude19:08:00

You can try the uberjar branch:

$ bb -cp $(clojure -Spath) --uberjar foo.jar -m proj
Building uber jar: foo.jar
$ bb -jar foo.jar
:foo - failed: int?

borkdude19:08:29

Maybe it will be confusing that .jar files compiled with bb cannot be run with Java because there is no compiled class, it's just a zip with clojure source files and a MANIFEST that says what the main namespace is

borkdude19:08:04

But it's still a jar file

borkdude19:08:53

What I mean is:

[email protected] /tmp/proj $ bb -jar foo.jar
:foo - failed: int?
[email protected] /tmp/proj $ java -jar foo.jar
Error: Could not find or load main class proj
Caused by: java.lang.ClassNotFoundException: proj

nate19:08:05

Hm. Maybe a little incompatibility is in order, have bb jar files be .bar files?

nate19:08:35

Maybe not. Don't like the PTSD from .war fikes back in the day.

borkdude19:08:20

But vice versa will work, uberjars compiled with Clojure (and bb compatible code) can be run with bb

borkdude19:08:04

Yeah, I guess the warning from Java is clear enough. It doesn't contain a class file.

nate19:08:27

I agree.