Vscode creates the Maven project

Because, I am studying design pattern recently, and I am reading the PDF book “Relearning Design Pattern” to summarize and summarize, of course, I still need to think in many aspects and angles, design pattern focuses on its ideas, and apply its ideas to real life or a certain scene of development.

Another point is that ALTHOUGH I use go language in my work, I do not want to use Goland, which is too heavy for me, so I am used to using VScode. I used to write python and JS a lot before, and I also use VScode to write Markdown. Therefore, AS for Java, I started to use VScode since then, without considering IDEA. Still too heavy…

Without further ado, start the show…

The premise

I wanted to start directly with vscode plug-ins, but I would like to mention Java language installation first.

I’ll start with the MAC platform. Of course, there are a lot of tutorials on the Web that explain how to install the Java language. I won’t go into the details here.

The MAC comes with Java, so you can use terminal input

java -version
Copy the code

The problem is that the MAC doesn’t have Java. If you do, you can ignore this part.

Take the path of the Java is commonly: / Library/Java/JavaVirtualMachines

Here are some tips to use Jenv to manage your Java version, but I’ll post the download address for the Java version image here

Java version image download address

Download and unzip to the path mentioned above…

Ok, add the environment variable, just to be clear, I’m using oh-my-zsh, so you can add it in.zshrc, but you can add it in.bash_profile.

As shown above, I can post the code to make it easy to copy, but of course, you can learn from it

#Added by Java JDK 1.8JAVA_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _181. JDK/Contents/Home PATH = $JAVA_HOME/bin: $PATH:. CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:. export JAVA_HOME export PATH export CLASSPATHCopy the code

Once you have done that, you need to brush the environment variable with source. ZSHRC, and you can use Java-version to get the scenario shown above.

Of course, I use Jenv to manage multiple versions of Java, and for installing Jenv, I naturally use Brew for MAC:

brew install jenv
Copy the code

Then, as in Java, add environment variables, and of course, when you install, the terminal will prompt you to add environment variables to the XXX file:

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
  eval "$(jenv init -)"
Copy the code

At this time I input jenv in the terminal, you can see a picture

If all of the above is ok, we can add the version, we can use Jenv Add, I can give an example, demo version 11, big guys can draw a conclusion:

Jenv add/Library/Java/JavaVirtualMachines/JDK - 11.0.12 + 7 / Contents/HomeCopy the code

Once added, you can type Jenv versions on the terminal

Switch to Jenv Global 11.0 or Jenv Local 11.0

No more nonsense, after all, what article is this? Create maven project with VSCode… The core is here…

If you have the Maven framework installed on your system, you can still install it on Mac OS using BREW

brew install maven
Copy the code

Of course, in addition to BREW, you can also go to the official website to download the binary file, remember to fill in the environment variables

Speaking of environment variables, you can add a patch to.zshrc, or you can add a soft link to the corresponding bin file in /usr/local/bin

After the above operation, you can enter MVN on the terminal to see the effect

Vscode about Java plug-ins

A diagram to solve, more convenient

After installing the plug-in, press Ctrl+Shift+P and enter Java: Configure Java Runtime

Check the project, project, and other runtime versions

Type setting.xml and the executable file for vscode’s maven plug-in, as shown below

If you want to test, it’s not impossible to demonstrate a simple project

Use CMD +shfit+ P to enter Java: Create Project, enter the Project name, in the SRC folder, select Run to Run the Java code, console data Hello World is successful.

Creating a Maven project

There are two ways:

The first kind of

Use CMD +shfit+p to enter Java: Create Project, or to create the Project type, we select Maven, let me show you how to create a Project using the first method…

In fact, I feel similar to the idea create Maven engineer, nothing more than to select the corresponding Maven project, then select the version, and then type a variety of ID names, etc., so the idea create maven project is similar…

However, having said that, the GIF above is only the first step, because after you type in some information, vscode’s debugging or terminal area will still allow you to confirm some information, such as

Follow the instructions step by step, I won’t show the GIF here.

The second,

In the second way, it is easier to add a + sign in the figure below

Father and son engineering

Based on the Maven project created above, we first have such a parent project, parent-Demo

Add a line of code to the parent project’s POM file and save it. Remember to recompile the POM.

<packaging>pom</packaging>
Copy the code

Next, we add subprojects

Finally, let’s look at the following figure:

As you can see from the figure above, the parent project POM file is automatically added

<modules>  
  <module>child-demo001</module>
</modules>
Copy the code

While sub-project POM files are added automatically

<parent>
  <artifactId>parent-demo</artifactId>
  <groupId>com.example</groupId>
  <version>1.0 the SNAPSHOT</version>
</parent>
Copy the code

We test engineering, we test automatically generated code

package com.example.child.demo;

/** * Hello world! * * /
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!"); }}Copy the code

From the picture above, we can print Hello World as we expect, yes, no problem at all.

summary

To sum up, I feel that there is no difference between idea and vscode tool. If you are familiar with it, you will soon master the use of it.