How To Use Yeoman To Scaffold Java Spring Project

Yeoman is an open-source tool that can help you to create different project skeletons easily and quickly. It contains a yo command-line tool and a lot of structure/template generators to create different project file skeletons ( etc java project, spring boot project). This article will tell you how to use it to create a java project structure and a spring boot project structure.

1. Install Yoeman.

  1. Yoeman contains a command-line user interface( yo ) written by Node js, so we should use npm to install Yoeman as below.
  2. Open a terminal and make sure npm has been installed on your machine.
    $ npm -v
    6.0.0
    
  3. Install yo with npm in the terminal. You had better install it with the root user, the root user has full file permission. When the command is complete, you can find yo module in folder /usr/local/lib/node_modules.
    $ sudo npm install -g yo
    

2. Install Structure/Template Generators.

  1. After installing the yo command tool, you also need to choose which project structure/template generator that you want to use.
  2. Open a web browser and go to search yeoman generators web site.
  3. Input keyword java in the search box, then it will list all related project structure/template generators on the page.
  4. I choose the jvm generator in this example, it can create java related projects. The generator name is generator-jvm. You can click the link to go to it’s GitHub website.
  5. Now run the below command in the terminal to install the generator-jvm java project generator.
    $ sudo npm install -g generator-jvm
  6. When the above command is complete, you can find generator-jvm has been installed in folder /usr/local/lib/node_modules/ also.

3. Create Java Project Structure Files.

  1. Now both the yoeman command-line tool yo and the java project template generator have been installed successfully. It’s time to create java project starter structure files.
  2. Create a folder where your want the java project saved.
  3. CD into the above folder.
  4. Run the below command to create the java project.
    $ yo jvm --name VSCJavaProect --type java
    
  5. After the above command, folder VSCJavaProject has been created, there are a lot of java project-related files in it.
  6. To create a java spring boot project run the below command.
    $ yo jvm --name VSCSpringBootProject --type java-spring-boot
  7. If you want to generate other java, scala, or kotlin type project, you can run the command $ yo jvm.
  8. It will first list all the project templates to let you choose, and then prompt you to input the project name after you select the template. Then it will create the project folder with the input name and save all the template files in it.
    192:VisualStudioCodeProject $ yo jvm
         _-----_     
        |       |    ╭──────────────────────────╮
        |--(o)--|    │  Welcome to the terrific │
       `---------´   │  jvm generator v1.18.64  │
        ( _´U`_ )    ╰──────────────────────────╯
        /___A___\   /
         |  ~  |     
       __'.___.'__   
     ´   `  |° ´ Y ` 
    ? What kind of project do you wanna build today, my friend? 
      scala-sbt-akka-actor 
      java 
      java-akka-actor 
    ❯ java-ee
      java-ee-cdi-full-multi-project 
      java-ee-ejb-full-multi-project 
      java-ee-faces 
    (Move up and down to reveal more choices)
  9. Now you can use your favorite IDE to edit, build and run the project. We will tell you how to debug such a java project using visual studio code in the next article.

Reference

  1. How To Install / Uninstall Node JS, NPM On Mac
  2. How To Install Node JS In Windows
  3. How To Use Node Package Manager

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.