I am working on an updated edition of my 2012 book “Java Web Database Application Development” (
https://javawebdb.wordpress.com/) which will use SpringBoot, JPA/Hibernate and Thymeleaf. My open-source project at
https://github.com/hhyde007/RADSpringBootGen features a complete sample application built this way.
With the moderator's permission I would like to preview some content here to see if the CodeRanch hands find this valuable and/or have any constructive criticism to offer.
I start out with a Chapter Zero for people with no prior Spring Boot experience. And since before working with Spring Boot one has to know the rudiments of
Maven, Ant or Gradle, I start with a review of Maven.
So my actual topic for this post is Maven, if you are interested.
My proposed content is:
[COPYRIGHT 2019 by Howard Hyde. All rights reserved]
Essential Tutorials (in this order)
There are many good technical tutorials available, in fact so many that it can be difficult to nail down the ones that are most essential for one’s mission. The ones listed below are the ones that I recommend for our present purposes, more or less in the given order.
By the way, take all the time you need. The tutorial may state that you can learn this in 15 minutes, and if you can do it in just 5, that’s great, but if instead you really need 5 hours to get into the material hands-on and with variations, take the 5 hours without apology. I frequently think of the analogy of the musician who, even though he or she “knows” the scales, still practices them, polishes them, refines them daily, even 20 years into a professional career.
Maven Build Tool Tutorials
• https://spring.io/guides/gs/maven
• https://www.baeldung.com/maven
IF YOU DON’T KNOW MAVEN, DON’T SKIP THIS STEP! It is essential to have a basic understanding of Maven for all of your work with Spring Boot and Spring Tool Suite (STS). Maven is the build tool of choice for Spring apps (Gradle is an alternative if you or your manager prefers).
Comments on these tutorials and on Maven generally
IMHO the two tutorials listed here are tied for first place as the clearest and most concise explanations of what Maven is, what it does and how it does it that I have found. I recommend you go through both of them; they overlap on several points, but take different approaches. Just as two eyes facilitate 3-dimensional vision, the enrichment of a second presentation of the same topic can be a force-multiplier of your understanding. Again, I wish I had seen these the first time I heard of Maven; it would have saved me a bundle in headache medication.
You won’t use every feature even of these simple getting-started tutorials right away; but they will give you a strong foundation upon which to build your skills.
If you’ve never used a build tool like Ant, Gradle or Maven before, you may be wondering, when do I execute javac (
Java Compile) at the command line? The answer is, you don’t. The build tool does that for you, in this case Maven via the mvn compile and/or mvn package commands; and it handles all of the internal class and external library/JAR dependencies based on the information you provide it in your pom.xml file.
Point to highlight: “INFO: You might like to consider using the Maven wrapper to insulate your developers against having the correct version of Maven, or having to install it at all. Projects downloaded from Spring Initializr have the wrapper included. It shows up as a script mvnw in the top level of your project which you run in place of mvn.”
That’s an important point, failing which otherwise once you get into developing in Spring Tool Suite (STS) using that IDE’s project model, you may be confused as to “but where is Maven?”
Note on Dependency Management and Repositories: As a hacker coding in your parents’ garage, you are free to download, import and run libraries/JARs from their original public repositories. From your cubicle behind a corporate firewall, however, you may be limited as to what libraries you are permitted to download and/or what versions thereof, into an internal corporate repository. Your company may have policies and processes for certifying external libraries for security and compatibility purposes. The versions of individual libraries/JARS that are Auto-configured by Spring Boot may or may not be available to you, requiring you to override the version property with a specific number that is available; and then that version of that component may be incompatible with other components, the versions of which are available to you. Headache!
Again, take your time and don’t hesitate to take the side trips for enrichment by clicking on external links, like for example the one on Semantic Versioning:
https://semver.org/.
What could possibly go wrong?
Just don’t, don’t, don’t, don’t – don’t panic! The first and second [ERROR] messages are your guides to how to fix the problem, in this case, “reached end of file while parsing”.
I left the closing curly brace off the end of my HelloWorld.java listing, so I have an invalid, un-compilable class definition. You may have a different Java syntax error to fix. In my case, a single character, a file save, and…
What could go right?
Pop Quiz: Do you know what an artifactId is?
If your answer to that question is not “Of course!” then review the tutorials above and/or read this mini-refresher:
The essential definition of your project comes in this form:
• GroupId: Group or organization creating/publishing the project, expresses as a reversed domain name
• ArtifactId: This will becom the name of your JAR (or WAR) file, comprising your complete application.
Burn those concepts into your brain; you are going to see them again and again. They apply to your project and to the external dependencies and resources that you include in your project.
Other Maven resources:
Skip these for now if you think you’ve got enough information to do your work; come back to them for enrichment or if you find yourself struggling with Maven-related issues down the road.
• https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
• https://maven.apache.org/guides/getting-started/index.html
• http://tutorials.jenkov.com/maven/maven-tutorial.html