Hi, in this video we're going to create a new Maven project for our microservice.
This will allow us to consistently build our application on different machines.
The Apache Maven project will also help us later when we add our code to our continuous
integration process.
We're going to start with no code, and get a simple microservice running using Wildfly
Swarm.
This tutorial will just be on the application side.
What that means is, we're not connecting the continuous integration parts just yet.
This is the second video in a larger playlist for creating microservices in Java.
You can find the link for the full playlist in the text below.
Here's our plan for this video.
We'll create the Java project using the Maven quickstart archetype.
We'll make some changes to the Maven POM file to incorporate Wildfly Swarm, and then we'll
compile and test it to make sure everything is set up correctly.
Our Java microservice won't do anything yet, but this will make it easy for us to package
our application as we add functionality.
Lets start creating our new maven project.
We're at a blank slate, so we'll create a project using a basic Java JAR archetype in
Maven.
At a command prompt, here's what we'll enter.
This will create a basic Java JAR project.
If you're not familiar with Maven, you might want to check out the Maven tutorials on DeegeU.com.
We'll accept the defaults for the version for now.
When it's done, there's nothing added in our POM file other than JUnit.
Now that we have created a new Maven project, we need to set up our project to use Wildfly
Swarm.
Wildfly Swarm has everything we need to create a Java application in a single JAR.
Swarm also provides other useful tools for implementing microservices in Java.
Wildfly Swarm does provide a wizard to create projects depending on our requirements, but
we're going to manually add dependencies to our POM file.
We're doing it manually only so we better understand all the moving parts, but if you
use Swarm for other projects, feel free to use the generator.
It's pretty cool!
First, we need to change the Maven packaging to war.
The reason is technically we're building a web application.
What will happen if we forget to change this is, it won't trigger JAX-RS to look for our
REST application.
When we try to access endpoints, nothing will happen.
Next we'll create a properties section in our POM file and add our first property.
It's the WildFly Swarm version.
At the making of this video, the current version is 1.0.0.Final.
We'll also add a property for the source encoding.
For almost everyone, it's UTF-8, but adding this gets rid of a Maven warning.
We need to make sure Maven is using Java 8 for everything, so we'll set the properties
for that.
The failOnMissingWebXml property is because Maven complains when you do not add a web.xml
file.
That's to tell Maven we don't need the web.xml file.
Next we need to add the dependency for Wildfly Swarm using these Maven coordinates.
This tells Maven to include Swarm libraries for our microservice.
The version is set from the property we defined in our properties section.
In order to package our microservice into one uber jar, we need to tell Maven how to
build our application.
We get that functionality by adding the wildfly-swarm-plugin.
This is what our POM file looks like so far.
Let's build it to make sure everything is right.
That command is mvn clean install.
It might take a while for the first time compiling.
Maven is downloading everything we need to implement the microservice.
If everything is setup right, we should BUILD SUCCESS in the info logs from Maven.
That's all there is to creating a new Maven project in Java.
This setup allows us to build the code on any machine.
It also imports easily in NetBeans.
Thanks for watching the video.
You can find the code on GitHub, and the complete transcripts on DeegeU.com.
Next we'll take a look at the design to our Trivia microservice.
If you like what you're seeing or have any questions, let me know in the comments or
on DeegeU.com!
See you in the next tutorial!