编程语言
首页 > 编程语言> > [Java-01] Mac-Maven-VSCode-配置&编译

[Java-01] Mac-Maven-VSCode-配置&编译

作者:互联网

Mac-Maven-VSCode-配置&编译

1: mac 安装java 1.8

参考链接:https://www.jianshu.com/p/5b5dcbf3f7d8

编辑java全局路径
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#  java -version
bmwdeMacBook-Pro:~ bmw$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
bmwdeMacBook-Pro:~ bmw$ 

2. 下载maven

参考链接:https://blog.csdn.net/weixin_43974907/article/details/107916386

  • 将下载的apache-maven-3.8.2 解压在mac 目录下
# /Users/bmw/apache-maven-3.8.2 为解压目录路径PATH
export MAVEN_HOME=/Users/bmw/apache-maven-3.8.2
export PATH=$MAVEN_HOME/bin:$PATH
# mvn -v
bmwdeMacBook-Pro:~ bmw$ mvn -v
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /Users/bmw/apache-maven-3.8.2
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

3. 配置VSCode

参考链接: http://www.littleblog.cn/javaee/7089.html

# 下载完基本上这些插件都会存在.
Language Support for Java(TM) by Red Hat
Debugger for Java
Java Test Runner
Maven for Java
#  步骤
1:打开设置(command + ,),搜索maven
2: 选择 Extension -> Maven for Java -> Edit in setting.json
3: 填写 "java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home"

# mac java.home 地址获取:
bmwdeMacBook-Pro:~ bmw$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home

4. 首次使用VSCode创建第一个java项目

groupid 一般分为多个段,这里我只说两段,第一段为域,第二段为公司名称, 虽然产生的项目结构文件与groupId无关,但是大家公认的规范是填写项目包名,如com.xx.testArchetypeGenerate(公司网址反写+项目名)
artifactid 填写你负责的模块名,如项目名-模块名
version 版本号
package 填写你创建的类所在的包名

例如:
groupid: com.bmw.createjavademo01
artifactid: createjavademo01-login
version: 1.0.0
package: 默认回车

5: 开始build java 项目

// 如:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug(Launch) - Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Debug(Launch)-App<target>",
            "request": "launch",
            "mainClass": "target.App",
            "projectName": "target"
        }
    ]
}

标签:Maven,01,java,VSCode,maven,version,bmw,Java
来源: https://www.cnblogs.com/comefromchina/p/java-maven-vscode-configuration.html