Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure and use Java in VSCode

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to configure and use Java in VSCode, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1 vs code

Also just contacted vs code, but fell in love at first sight.

Recently, I have been trying to use nim language, and vs code is recommended. I tried it for a while, and then it got out of hand. So I have a bold idea, just turn it all to vs code. What's the situation now? How troublesome it is to use webstorm/sublime,java with idea,python with PyCharm, ruby with RubyMine and c # with vs express.

Vs code is actually the editor, is a vest, but various languages can implement the corresponding plug-ins, packaged into an ide, which is very good, very advanced! The most important thing is, open source, free!

1.1 what is IDE

The integrated development environment (IDE,Integrated Development Environment) is an application used to provide a program development environment, which generally includes tools such as code editors, compilers, debuggers, and graphical user interfaces. The development software service set integrates the code writing function, analysis function, compilation function, debugging function and so on.

Such as Microsoft's Visual Studio series, as c++/c# IDE

IDE of Java, such as Eclipse and IntelliJ IDEA.

1.2 VS code is an editor

Vs code is not an IDE, it is an editor, it is an ideal editor that can be packaged as an IDE through plug-ins in the corresponding language.

Vi is also an editor, and many programmers use vi for development and build with independent tools such as make,ant,maven,gradle and so on. Ctags is used to index symbols in the source code.

So what kind of editor is good for programmers?

Open the file, convenient and fast, syntax highlight, beautiful!

Editor: add, delete, change and search, rich and quick

Symbols: symbols define queries, jumps, symbol references.

Dependency management: automatically import dependency packages

Analysis: class structure, inheritance relationship.

Automatically prompt...

Other advanced features.

Some of the above features can be done by vs code, and some must be done by plug-ins. For example, symbols and dependency management related to language features, it must be done by the corresponding language plug-ins, you can not use vs code, because the code can not jump to definition, scold vs code is not smart.

2 java

Although the idea experience is good, it sometimes feels too bloated and not smooth enough.

Of course, it must be admitted that vs code can't match the complete features provided by idea, and idea/eclipse is definitely the only way for beginners. However, as programmers, we must also be aware that design is a trade-off, and the meticulous nanny-like graphical interface provided by idea will eventually seem friendly but verbose, and one day, when you grow up, you will find her verbose.

2.1 java support extensions

Https://code.visualstudio.com/docs/languages/java

According to the official documentation, honestly install the extensions related to java.

To put it simply:

VS Code Java IDE =

Editor: vs code build tool: maven/gradle language support: Eclipse ™JDT Language Server

2.2 Language Support for Java ™by Red Hat

Some features such as:

Code completion: code completion

Automatic import: organize imports

Code Jump: code navigation

Wait! Obviously, vs code does not provide these language-level features, which is why JetBrains has so many products:

IntelliJ IDEA-A set of intelligent Java integrated development tools that focus on and emphasize programmers' development and writing efficiency.

PHPStorm 7.0Releases, PHP integrated development tools

PyCharm 3 release, intelligent Python integrated development tool

RubyMine-RubyMine is an IDE for Ruby and Rails developers with all the necessary features and tightly integrated into a convenient development environment.

WebStorm8.0 release, intelligent HTML/CSS/JS development tools

Vs code provides the corresponding IDE features through extension, which is what the Language Support for Java ™by Red Hat extension does for Java.

Provides Java ™language support via Eclipse ™JDT Language Server, which utilizes Eclipse ™JDT, M2Eclipse and Buildship.

2.3 what is JDT

JDT is called Eclipse Java Development Tools.

The JDT project provides the tool plug-ins that implement a Java IDE supporting the development of any Java application

Let's take a look at what JDT core provides that vs code needs to extend:

A Java Model that provides API for navigating the Java element tree. The Java element tree defines a Java centric view of a project. It surfaces elements like package fragments, compilation units, binary classes, types, methods, fields.

A Java Document Model providing API for manipulating a structured Java source document.

Code assist and code select support.

An indexed based search infrastructure that is used for searching, code assist, type hierarchy computation, and refactoring. The Java search engine can accurately find precise matches either in sources or binaries.

Evaluation support either in a scrapbook page or a debugger context.

Source code formatter

It is important to note that the extension uses an Eclipse IDE-related implementation. When you generate a new java project, such as generate a HelloWorld project through mvn:

Mvn archetype:generate-DarchetypeGroupId=org.apache.maven.archetypes-DarchetypeArtifactId=maven-archetype-quickstart-DarchetypeVersion=1.3

Then open the project directory with vs code, and you will see that several files and directories are generated in the project directory:

1 .settings

1.1 org.eclipse.jdt.core.prefs

"eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.6"

1.2 org.eclipse.m2e.core.prefs

"activeProfiles= eclipse.preferences.version=1 resolveWorkspaceProjects=true version=1"

2 .project

Spring-ldap-user-admin-sample org.eclipse.jdt.core.javabuilder Org.eclipse.m2e.core.maven2Builder Org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature

3 .classpath

Note: these files are automatically generated by extension, if the corresponding files are not generated under the directory, then there will be a variety of problems, many jdt-related features can not be used normally, such as symbol jump, automatic import and so on.

If you open a java project with IDEA, you will also create a similar file, but with a different structure and name.

2.4 Java Classpath is incomplete. Only syntax errors will be reported

If you encounter this warning, there is something wrong with the java project during the opening process, and the .classpath .project file is missing. There may be the following reasons, such as:

Jdt related extentsions is not installed

The java environment is not configured according to the official instructions

Extension configuration is incomplete

In this case, the symbol jump, automatic completion, import and other functions, certainly can not be used normally.

But there is no problem with using mvn to build, it must be clear that mvn is a build tool, as long as the source code is complete and correct, with pom.xml files, then maven will work properly.

In addition, it is found that when the project supports both maven and gradle, vs code will fail to create the project, resulting in the failure of classpath-related files. At this time, delete the build.gradle, leave only the pom.xml file, and open the project folder again.

2.5 Project structure

As shown in the figure above, a java project that starts normally needs to include

JAVA PROJECTS

MAVEN PROJECTS

JAVA DEPENDENCIES

Java Projects contains .classpath, .project, .settings

These are all the contents of the article "how to configure and use Java in VSCode". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report