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.
- Yoeman contains a command-line user interface( yo ) written by Node js, so we should use npm to install Yoeman as below.
- Open a terminal and make sure npm has been installed on your machine.
$ npm -v 6.0.0
- 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.
- After installing the yo command tool, you also need to choose which project structure/template generator that you want to use.
- Open a web browser and go to search yeoman generators web site.
- Input keyword java in the search box, then it will list all related project structure/template generators on the page.
- 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.
- Now run the below command in the terminal to install the generator-jvm java project generator.
$ sudo npm install -g generator-jvm
- 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.
- 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.
- Create a folder where your want the java project saved.
- CD into the above folder.
- Run the below command to create the java project.
$ yo jvm --name VSCJavaProect --type java
- After the above command, folder VSCJavaProject has been created, there are a lot of java project-related files in it.
- To create a java spring boot project run the below command.
$ yo jvm --name VSCSpringBootProject --type java-spring-boot
- If you want to generate other java, scala, or kotlin type project, you can run the command
$ yo jvm
. - 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)
- 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
- How To Install / Uninstall Node JS, NPM On Mac
- How To Install Node JS In Windows
- How To Use Node Package Manager