前篇搭建了最简单的可以调试Java代码的环境,本文将配置VSCode的Maven环境,使导入仓库包更方便。

  1. 首先配置可以正常使用的Maven环境。
  2. 新建一个临时空目录,在其中创建必须的几个文件和文件夹,包括“pom.xml”、“src/main/java”。TIM截图20180227103830.png
  3. 修改VSCode中与Maven相关的配置,将Maven可执行文件(windows平台为“mvn.cmd”)的绝对路径填写在“maven.executable.path”配置项中,并将Maven配置文件“settings.xml”的绝对路径填写在“java.configuration.maven.userSettings”配置项中。TIM截图20180227104002.png
  4. 保存配置并重启VSCode,之后在“pom.xml”文件上右击,并选择“Update project configration”。TIM截图20180227104817.png
  5. 之后,VSCode的Java插件将会在工作区中生成相关的文件(“.classpath”、“target”等)。TIM截图20180227104225.png
  6. 在工作区下方,即可选择Maven工程的常用命令。TIM截图20180227104447.png
  7. 配置完成后,代码中可直接提示出“pom.xml”包含的包中的类。TIM截图20180227104601.png

标签: none

已有 4 条评论

  1. Hi admin , I am trying use VSCode to bulid java project. And I tried use below codes:
    public class Main{
    public static void main(String[] args){
    System.out.println("test");
    }
    }
    And when i run, it gives me a error:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at Main.main(main.java:2)
    After that I tried use the cmd javac to compile the .java file, and it compile successfully, and run the class it turn out the test word.
    I delete the public before the class in line 1 and it worked.
    ---------------------------------
    I didn't know why, please tell me when you are free. Thanks for your time.

    1. It maybe true that some unknown problems existed in the VSCode or Java plugin. And I have not tried any development with VSCode for a long time. Please change the Java IDE to IDEA or Eclipse. Thank you for your visit.

    2. 123 123

      try:make your class name be same to your filename.(classname = Main filename = Main.java)

  2. Jinx Jinx

    hi

添加新评论