tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
2020-06-11T19:27:02.316400Z

I am looking for something like a maven api that I can call from a Clojure app to make a .jar from a java file + itโ€™s main class name. Iโ€™ve never used maven directly (at least not in anger). Any opinions here? For context: I am making a .jar and uploading it to a lambda-like service. Not about tool deps so I hope this is OK - seems like the place where I am most likely to get answers ๐Ÿ™‚ Please reply in the thread

2020-06-12T07:42:29.321300Z

If you want the jar to be executable via java -jar my.jar rather than java -cp my.jar my.MainClass youโ€™ll also need to put a META-INF/MANIFEST.MF file in there with the contents:

Manifest-Version: 1.0
Main-Class: my.MainClass

1
2020-06-11T19:27:18.316500Z

Please reply here to keep the channel tidy ๐Ÿ™‚

dominicm 2020-06-11T19:28:33.316700Z

@nha What service are you using? I created an AWS lambda-specific output for pack and would be interested in targetting others.

2020-06-11T19:29:04.316900Z

itโ€™s actually pulsar Functions http://pulsar.apache.org/docs/en/functions-overview/

2020-06-11T19:30:03.317200Z

So hence lambda-like, itโ€™s not exactly the same. However they accept a

--jar target/my-jar-with-dependencies.jar \
  --classname org.example.functions.WordCountFunction \

dominicm 2020-06-11T19:31:04.317400Z

OK, looks like you need an uberjar of some kind in that case. I would recommend the library @seancorfield maintains for that.

dominicm 2020-06-11T19:31:47.317600Z

There's downsides to uberjars (which is why pack doesn't produce them), I'm curious to know if they accept anything else, so I'm reading the docs now :)

2020-06-11T19:34:57.317800Z

is this the lib? https://github.com/seancorfield/depstar

dominicm 2020-06-11T19:37:00.318100Z

That's the one :)

1
dominicm 2020-06-11T19:37:21.318400Z

Doesn't look positive for alternative forms. Unfortunate. Depstar is what I'd recommend :)

2020-06-11T19:41:56.318600Z

depstar looks like it is supposed to be used from the CLI, and not sure it supports .java files? I am looking for something to embed. I could always shell it / reach into the namespaces though

2020-06-11T19:43:01.318800Z

well the api looks simple enough :simple_smile: https://github.com/seancorfield/depstar/blob/master/src/hf/depstar/jar.clj#L9

dominicm 2020-06-11T19:43:34.319100Z

Oh, sorry, I thought you wanted to make a jar for clojure

dominicm 2020-06-11T19:43:37.319300Z

apologies

dominicm 2020-06-11T19:43:43.319500Z

Right, you don't need much at all

dominicm 2020-06-11T19:43:58.319700Z

javac MyFile.java then zip jar.jar MyFile.java

dominicm 2020-06-11T19:44:01.319900Z

that's it, you're done!

dominicm 2020-06-11T19:44:11.320100Z

there might be an official java tool for making a jar, but zip works OK

seancorfield 2020-06-11T19:44:13.320300Z

@nha To build uberjars with depstar, you should be able to depend on the library and call hf.depstar.uberjar/run with the appropriate options -- see how the -main function sets those up. It assumes there's a pom.xml file available because it uses the presence of that to trigger some of the AOT and manifest generation stuff. It assumes, at a minimum, you've run clojure -Spom in a project, but you could probably generate a stub pom.xml as a temp file and pass that in.

seancorfield 2020-06-11T19:45:15.320500Z

And depstar works from the classpath -- so it will build a JAR from whatever is on your classpath which is very likely not what you're looking for ๐Ÿ™‚

seancorfield 2020-06-11T19:45:55.320700Z

jar is the "official Java tool for making a jar" but it's basically just zip ๐Ÿ™‚

2020-06-11T19:46:10.320900Z

Ahah I see ๐Ÿ™‚ not what I am looking for indeed. Shelling to javac or even mvn looks like it could be the way then

2020-06-11T19:46:40.321100Z

I found this http://maven.apache.org/ref/3.1.0/maven-embedder/index.html but I fear it may be a can of worms ๐Ÿ˜„