Home >Development Tools >VSCode >Teach you step by step how to create a maven project in vscode (combination of graphics and text)

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

青灯夜游
青灯夜游forward
2021-10-13 19:08:5512017browse

How to create a maven project in vscode? The following article will take you step by step to create a maven project through a combination of pictures and texts. I hope it will be helpful to you!

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

Because I am currently learning design patterns, and I am reading the pdf book "Relearning Design Patterns" to summarize and summarize. Of course, I still need to think about it from many aspects and angles. , the design pattern focuses on its ideas and applying its ideas to real life or a certain development scenario.

Another point is that although I use the Go language for work, I don’t want to use Goland. I think it’s too heavy, so I’m used to using vscode. I used to write a lot of python, js, etc., and I also use it to write markdown. vscode, so, like Java, I have started to use vscode since then. I don’t think much about using IDEA. I still think it is too heavy...

Without further ado, let’s start the show...

Premise

I wanted to start directly with the plug-in on vscode, but it seems that I have to mention the installation of Java language first... [Recommended study: "vscode tutorial" 】

I will start with the mac platform. Of course, there are a lot of tutorials on the Internet about the installation of the Java language, so I will not introduce it in detail here.

Mac comes with java, you might as well enter in the terminal

java -version

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

The problem you may encounter is: the built-in mac does not have java. If you have, This part can be ignored...

The path of the built-in java is generally: /Library/Java/JavaVirtualMachines

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

Yes It doesn’t matter if you don’t have it. Let me teach you a trick to use jenv to manage your java version, but I will post the java version mirror download address here

java version mirror download Address

https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/

After downloading, extract it to the path mentioned above...

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

ok, add environment variables, let me declare here, I am using oh-my-zsh, so you can add it in .zshrc, Of course, you can add it in .bash_profile.

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

As shown in the picture above, I can paste the code into the text for easy copying. Of course, you can draw inferences

# added by java jdk 1.8
JAVA_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 CLASSPATH

After performing the above operations, you need to usesource .zshrc Refresh the environment variables. At this time, you can use java -version, and the scene shown in the above picture will appear.

Of course, I use jenv to manage multiple versions of java. Regarding how to install jenv, I naturally use mac’s brew:

brew install jenv

Then, like java, add environment variables. Of course, after you install the terminal, you will be prompted to add environment variables in the xxx file:

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

At this time, I enter jenv in the terminal , you can see the screen

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

If the above is ok, we can add the version, we can use jenv add, I can give you an example For example, the demonstration is version 11. You can draw inferences:

jenv add /Library/Java/JavaVirtualMachines/jdk-11.0.12+7/Contents/Home

After the addition is successful, you can enter jenv versions

Teach you step by step how to create a maven project in vscode (combination of graphics and text)## on the terminal.

#Switch version:

jenv global 11.0 or jenv local 11.0

No more nonsense, what kind of article is this after all?

vscode creates maven project...The core is here...

Speaking of creating a

Maven project, the premise is that the maven framework is installed on your system. For Mac os systems, you can still use brew to install

brew install maven

. Of course, in addition to

brew, you can also download the binary file from the official website. Remember Add environment variables

Speaking of environment variables, you can add them in

.zshrc, or you can add the corresponding bin file in /usr/local/bin Soft link

After executing the above operation, you can enter

mvn in the terminal to see the effect

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

vscode About java Plug-in

One picture to solve, so convenient

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

After installing the plug-in, press

Ctrl Shift P and enter Java: Configure Java Runtime

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

检查项目、工程等运行时版本

给vscode的maven插件键入setting.xml和可执行文件,分别如下图所示

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

若想测试的话,也不是不可以,演示一下简单工程

使用cmd+shfit+p 输入 Java: create Project,输入项目名,在src文件夹中,选择Run运行Java代码,控制台数据Hello World则为成功。

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

创建maven工程

有两种方式:

第一种

使用cmd+shfit+p 输入 Java: create Project,或出现创建项目的类型,我们选择maven,这样吧,我动图演示一下,如何创建使用第一种方式创建maven工程的...

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

其实我感觉就跟idea创建maven工程师类似的,无非就是选择对应的maven工程,其次选择版本,然后键入各种id名称等,所以和idea创建maven工程大同小异...

不过,虽然我这么说了,但是上面的动图仅仅是第一步,因为你键入一些信息之后,vscode下面调试或者终端区,依然会让你确认一些信息,比如

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

按照提示,一步一步操作即可,这里我就不演示动图了。

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

第二种

第二种,比较简单,直接在下图中添加+号即可

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

父子工程

基于上面创建Maven工程的基础,那么,我们首先有这样的父工程parent-demo

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

在父工程的pom文件中加入一行代码,保存即可,记得重新编译一下pom。

<packaging>pom</packaging>

接着,我们添加子工程

1Teach you step by step how to create a maven project in vscode (combination of graphics and text)

最后,我们看以下图:

Teach you step by step how to create a maven project in vscode (combination of graphics and text)

从上图可以看出,父工程pom文件自动添加

<modules>  
  <module>child-demo001</module>
</modules>

而子工程的pom文件,自动添加

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

我们测试一下子工程,测试自动生成的代码

package com.example.child.demo;

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

2Teach you step by step how to create a maven project in vscode (combination of graphics and text)

从上图可以,按照我们的预期,是可以输出Hello World,是的,完全没得问题。

小结

综上,给我的感觉是和idea没什么区别,如果vscode工具比较熟悉的话,很快就掌握其中的使用了。

更多编程相关知识,请访问:编程入门!!

The above is the detailed content of Teach you step by step how to create a maven project in vscode (combination of graphics and text). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete