Now that we have a production ready Spring Boot microservice application in hand, let's see how we can build a distributable JAR file and run the jar file to achieve the same thing. So the first thing that we have to do is to go to our Eclipse and open the palm d'Or XML. The palm d'Or XML doesn't have dependency on hits to database, because we added directly from project properties. And then we add it via Java build path libraries. So we don't need this in this way. Because the Maven tool for installing all the dependencies looks only here so we don't want that to be missed out.
We can get rid of the h2 dependency from here. So I can say remove and then add the h2 dependency over here. To get the h2 dependency. Let's go back to the spring initializer. Let's add here h2. Click on this When I say explore the project, we will see the pom dot XML.
But this time, I don't want to copy the entire palm d'Or XML. But I just want to get the h2 database dependency. So I'm going to copy this and go back to eclipse. In somewhere in between, I'm going to paste this. The second thing is that because the h2 database is in the build path, Spring Boot automatically recognizes the h2 and then uses that as the driver. So we don't have to explicitly mention in our application dot properties, so we don't need this, I can just make it as a comment, save it.
And one last thing is to build the jar file by right click on the project or the XML file, run as Maven install. And this is going to create a distributable JAR file, reading all the dependencies from our POM dot XML. And finally it said here, build Success refresh target folder and say, expand, you'll see that there is a Spring Boot demo zero dot zero dot one snapshot dot jar. Now I can open up a command prompt, or terminal and then run this jar file. Let's go to the terminal, create a new tab. Let's get into desktop, where I have this project called developing restful services using Spring Boot.
And I have here a folder called workspace. That's where my project is there, which is called Spring Boot demo. Let's get into Spring Boot demo. And then I have here a target folder. So if you look at the target content, I have here Spring Boot demo snapshot dot jar. So all I have to do is to type Java minus jar, target slash Spring Boot demo.
So on so JAR file, now if I want to overwrite any properties from the application dot properties file, I can give that before the target location as dash capital D, server dot port equals to, for example, eight zero or anything of your choice. Now eight zero is the default port for HTTP protocol which which means you don't have to mention the port number by issuing the command. Now if this is okay, we should be able to see our Spring Boot console logs. And somewhere in between it should also say HTTP server started at port number eight, zero. And once this is done, if I go back to the postman and send this request, again 47777 we don't have this server running anymore. So it should not come back with an output it is could not get any response.
But either I can say here, eight zero or I can completely remove the poll Number and this time I should get the output properly.