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
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
Please reply here to keep the channel tidy ๐
@nha What service are you using? I created an AWS lambda-specific output for pack and would be interested in targetting others.
itโs actually pulsar Functions http://pulsar.apache.org/docs/en/functions-overview/
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 \
OK, looks like you need an uberjar of some kind in that case. I would recommend the library @seancorfield maintains for that.
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 :)
is this the lib? https://github.com/seancorfield/depstar
That's the one :)
Doesn't look positive for alternative forms. Unfortunate. Depstar is what I'd recommend :)
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
well the api looks simple enough :simple_smile: https://github.com/seancorfield/depstar/blob/master/src/hf/depstar/jar.clj#L9
Oh, sorry, I thought you wanted to make a jar for clojure
apologies
Right, you don't need much at all
javac MyFile.java
then zip jar.jar MyFile.java
that's it, you're done!
there might be an official java tool for making a jar, but zip works OK
@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.
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 ๐
jar
is the "official Java tool for making a jar" but it's basically just zip ๐
Ahah I see ๐ not what I am looking for indeed. Shelling to javac
or even mvn
looks like it could be the way then
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 ๐