Want this course?
Creating JARs with Boot
Course: JVM Fundamentals for Clojure
We learn how to create JAR files with Boot.
Alright. Let's take a look at how to use Boot to make JAR files. As you may know, if you use Boot, Boot is all about composing up tasks into bigger tasks. So ... The jar task is actually very simple. All it does is it puts stuff in the JAR file. So if you do boot jar, by itself, it's just gonna make that one JAR. And I think it's empty.
Now, if you wanna add stuff to it, you have to start adding stuff into the options such as the source path, the resource path, those kinds of things. There are a couple of options. So, let's look at it. The first one is file, so you can say what the output filename is. You can set some key values on the manifest, if you wanna do that. And you can also set the main ...
The main name space that has the dash main function in it, and it also will set the main class in the manifest for you. Okay, so this is useful for building the JAR, but it doesn't say what gets put in it really. You have to set your options to do that. So what you'll see often is something like ...
Well, first I need to aot, and I wanna aot all of it, and then I'm going to do uber to get all of my dependencies pulled in. And then I'm gonna do jar, and I'm gonna save it as my ... No, let's call it uberjar.jar, like that. Now that'll do all of those steps and save that JAR. Right, and the reason it's an uber JAR is because we do the uber step before we do jar. Now to demonstrate how this could become a task so you don't have to remember to type that whole thing every time, because that would get annoying, I've made a task. This is a Boot task called uberjar.
Now, there isn't one built in, so I made my own, and it just sets some common defaults. Because Boot is very explicit, which is a good thing. You have to say, well my code is in src, and my resources is in the resources, and both of these things will get put into the JAR. And then you also have some options for the different tasks. So I want the JAR filename to be uberjar.jar, and I am gonna give it the main of lab-notebook core. When I aot, I wanna aot everything, or you could optionally ... I'm gonna take that out.
You could optionally list all of them explicitly, but all true should work. And then I'm just gonna do those same sequence of things, of tasks, as I did on the command line. But this way they're all specified like this. So, there you go. There's also something called line pom ... I'm sorry, boot pom, which will create your pom file. It has some options that ... You wanna set the project and the version, right. It needs that. So we'll see those two options. And this is similar to the Leiningen pom command, except it doesn't know where to get them from. In Leiningen, it gets them from the project.clj.
In Boot, you have to give them as options. So, we can do pom -p, this project is called lab-notebook, I'll just leave it without quotes, and then the version is 0.1, there. And that should create the pom file, which you might wanna put in your uberjar too, so you can add that to the uberjar build task. Cool. This is Boot and JARs.