使用VSCode搭建简单Java开发环境(二、Maven环境)
前篇搭建了最简单的可以调试Java代码的环境,本文将配置VSCode的Maven环境,使导入仓库包更方便。
- 首先配置可以正常使用的Maven环境。
- 新建一个临时空目录,在其中创建必须的几个文件和文件夹,包括“pom.xml”、“src/main/java”。
- 修改VSCode中与Maven相关的配置,将Maven可执行文件(windows平台为“mvn.cmd”)的绝对路径填写在“maven.executable.path”配置项中,并将Maven配置文件“settings.xml”的绝对路径填写在“java.configuration.maven.userSettings”配置项中。
- 保存配置并重启VSCode,之后在“pom.xml”文件上右击,并选择“Update project configration”。
- 之后,VSCode的Java插件将会在工作区中生成相关的文件(“.classpath”、“target”等)。
- 在工作区下方,即可选择Maven工程的常用命令。
- 配置完成后,代码中可直接提示出“pom.xml”包含的包中的类。
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.
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.
try:make your class name be same to your filename.(classname = Main filename = Main.java)
hi