Yeoman is an open source tool which can help you to create different project skeleton easily an quickly. It contains a yo command line tool and a lot of structure/template generators to create different project file skeleton( 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, root user has full file permission. When the command complete, you can find yo module in folder /usr/local/lib/node_modules.
$ sudo npm install -g yo
2. Install Structure/Template Generators.
After install yo command tool, you also need to choose which project structure/template generator that you want to use.
- Open a web browser and goto search yeoman generators web site.
- Input keyword java in the search box, then it will list all related project structure/template generators in the page.
- I choose jvm generator in this example, it can create java related project. The generator name is generator-jvm. You can click the link to goto it’s github website.
- Now run below command in terminal to install the generator-jvm java project generator.
$ sudo npm install -g generator-jvm
- When above command 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 yoeman command line tool yo and the java project template generator has been installed successfully. It’s time to create java project starter structure files.
- Create a folder where your want the java project saved in.
- CD into above folder.
- Run below command to create the java project.
$ yo jvm --name VSCJavaProect --type java
- After above command, folder VSCJavaProject has been created, there a a lot of java project related files in it.
- To create java spring boot project run 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
$ yo jvmcommand. 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 use visual studio code in next article.
- How To Install / Uninstall Node JS, NPM On Mac
- How To Install Node JS In Windows
- How To Use Node Package Manager