Java Basic Development Environment Vscode build Windows Vscode compile run simple Java

Source: Internet
Author: User
Tags goto pack

JAVA Basic Development Environment Vscode build source https://www.cnblogs.com/freewsf/p/7744728.html

For Java developers who use Visual Studio Code, the Language support to Java (TM) by Red Hat extension provides very good language features, such as IntelliSense and project support. However, we also hear some user feedback that requires debugging Java programs. Today, we are excited to announce that we have partnered with Red Hat to develop a lightweight extension that allows developers to debug Java applications: Java Debugger for Visual Studio Code, which is based on Java debug Server.

Note: Java Debugger for Visual Studio code and Java Debug Server will be open source shortly after the initial release.

To enable Java developers to start using VS Code as soon as possible, we also created a Java extension package that contains the Language support for Java (TM) by Red Hat and Java Debugger for Visual Stu Dio Code These two extensions so that you do not need to go through the search to install these extensions separately. This is a modern Java workflow that is just beginning to be created and we will add more features and extensions to the Java extension package in the future.

Begin

Start with the following steps:

    1. Open the Extended view (ctrl+shift+x) in Visual Studio Code.

    2. Enter "Java" to filter the list of extensions.

    3. Locate and install the Java Extension Pack (Java expansion pack), or you can find and install the Java Debugger for Visual separately if you have installed Language support for Java (TM) by Red Hat Studio Code extension.

You can also install the Java extension package directly from this article:

Install the Java expansion pack (with Vscode installed, click on the link above to call Vscode for installation)

Restart Vscode, open the code that contains the Java project, and then follow the steps below:

    1. Prepare the project. Opens a. java file, and the Java extension is activated. Maven, Gradle, and Eclipse projects are supported. This extension will automatically build the project without the need to trigger the build manually.

    2. Start Debugging. Switch to debug view (ctrl+shift+d), open Launch.json and add Java Debug Configuration.

    3. Fill in the MainClass with the class you want to start, or fill in the HostName with the host name you want to attach and fill in the port.

    4. Set breakpoints and press F5 to start debugging.

Supported Features

In this release, we support the following features:

    • Start/Attach-you can start a Java project in VS Code, or you can attach to a JVM process that runs in debug mode on either the local or remote side.

    • Breakpoints-supports expression conditions or hit conditional breakpoints, which can be easily set in the built-in breakpoint settings container. So you can insert breakpoints directly in the source view, which is handy without having to pop up the container. It is also supported by an abnormal interrupt.

    • Control flow-Includes pausing, continuing F5, Stepping F0, stepping F11, stepping out (jumping out) shift+f11.

    • Data review-When the program stops on a breakpoint, the debugger can access the variable names and values in the current memory. Supports viewing/monitoring/setting variable values.

    • Diagnostics-The Call stack panel displays the program's call stack, where you can jump freely in the captured call path. Multithreaded debugging is also supported through and stacks.

    • Debug console-You can see standard output and error output information from the Debug console.

Official documents:

The Java support in VS Code are provided through extensions and optimized for lightweight Java projects with a simple, mode RN Workflow. Popular extensions in the Marketplace provide project support, code completion, linting, debugging, code formatting, Snipp ETS, and more.

Download vs Code-if you haven ' t downloaded vs Code yet, quickly install for your platform (Windows, Mac, Linux).

Install Java Extensions

VS Code is a fast editor and ships with only the basic features. ADD Java language Support to VS Code by installing the popular Java extensions.

    1. In Visual Studio Code, go to the Extensions view (ctrl+shift+x).
    2. Filter the extensions list by typing "java".

To help set up Java on VS Code, there is a Java Extension Pack which contains, popular extensions:

    1. Language support for Java (TM) by Red Hat
    2. Java Debugger for Visual Studio Code

Install the Java Extension Pack

This document describes the features included in the Java Extension Pack.

Java Project Support

Maven, Eclipse and Gradle Java project is supported through Language support for Java (TM) by Red Hat, by utilizing M2ECLI PSE which provides Maven support and buildship which provides Gradle support through the Eclipse JDT Language Server.

Please note that gradle-based Android projects is not supported.

Editing and Navigating Code

Linting

A linter is a tool which provides warnings for suspicious looking code. Language support for Java (TM) by the Red Hat provides this feature to the report parsing and compilation errors as you type, so yo u can fix them inside VS Code.

Intellisense

VS Code also supports code completion and Intellisense for Java through Language support for Java (TM) by Red Hat. Intellisense is a general term for a number of features, including intelligent code completion (In-context method and Vari Able suggestions) across all your files and for built-in and thirty-party modules.

Search for Symbols

You can search for symbols in the current file or workspace to navigate your code more quickly.

To search for a symbol in the current file, Use quick open  (ctrl+p" then enter the ' @ ' command and then enter the name of the ' the ' symbol of your ' re looking for. A list of potential matches would appear and is filtered as you type. Choose from the list of matches to navigate to their location.

To search for a symbol in the current workspace, start by pressing ctrl+t and then enter the name of the symbol. A list of potential matches would appear as before. If you choose a match this is found in a file that's not already open, the file would be opened before navigating to the M Atch ' s location. Alternatively, you can also use Quick Open (ctrl+p) and then enter the ' # ' command to search for the current workspace. Ctrl+t is just the shortcut for the ' # ' commands, respectively, so everything works the same.

Peek Definition

You can take a quick look at how a symbol is defined by using the Peek Definition feature. This feature displays a few lines of code near the definition inside a peek window so you can take a look without Navigati Ng away from your.

To peek at a symbol's definition, place your cursor on the symbol anywhere it's used in your source code and then press alt+f12. Alternatively, you can choose Peek Definition from the context menu (right-click, then choose Peek Definition).

Go to Definition

You can also quickly navigate to where a symbol are defined by using the Go to Definition feature.

To go to a symbol's definition, place your cursor on the symbol anywhere it used in your code and then press F12. Alternatively, you can choose Go to Definition from the context menu (right-click, then Choosego to definition). When there's only one definition of the symbol, you'll navigate directly to their location, otherwise the competing Definiti ONS is displayed in a peek window as described in the previous sections and you had to choose the definition so you wan T to go.

Other code editing features include:

    • Code formatting
    • Code Snippets
    • Code outline
    • Code Lens (References)
    • Javadoc hovers
    • Rename
    • Highlights
Debugging

Java Debugger for Visual Studio Code was a lightweight Java Debugger based on Java Debug Server. It works with Language support for Java by Red Hat to allow users debugging Java code using Visual Studio code (VS code).

The Java Debugger supports following features:

  • Launch/attach-you can either Launch the Java project within VS Code or Attach to any running JVM process in debug mode, Locally or remotely.
  • Breakpoints-conditional breakpoints by hits Count is supported and can easily be set using the inline breakpoint settings Window. This allows-conveniently add conditional breakpoints to your code, directly in the source viewer, without requiring A modal window. Break on exceptions is also supported.
  • Control flow-including Pause, Continue F5 , step over F10 , step to F11 , step outShift+F11
  • Data inspection-when you ' re stopped at a breakpoint, the debugger have access to the variable names and values that is C urrently stored in memory. Inspect/watch/set Variables is supported.
  • Diagnostics-the Call stack panel shows the "Call stack of your" and allows to navigate through the call path O F each captured allocation. Multi-threaded debugging is supported by parallel stacks.
  • Debug Console-the Debug Console lets you see information from both stdout and stderr.

You can launch the debugger following steps below:

    1. Switch to the Debug view (ctrl+shift+d).
    2. Open to launch.json Add a debug configuration for Java
    3. Fill in the mainClass to Launch setting or and for hostName port Attach .
    4. Click Start button or press to F5 Start debugging.

Next Steps

Read on to the find out about:

    • Basic Editing-learn about the powerful VS Code editor.
    • Code Navigation-move quickly through your source code.
    • Tasks-use tasks to build your project and more
    • Debugging-find out how to use the debugger with your project

Windows Vscode compilation runs simple Java

Note: Vscode currently does not support debugging Java, this article is only configured to run simple Java,blackkitty with Vscode compilation and does not write Java so this article is for entertainment only

first Look at the effect:

Configuration process:

    1. JDK & JRE Configuration (not detailed on the internet a lot)
    2. Vscode download installation as well as plug-in Cpptools installation (not detailed, see Blackkitty in another article in step 1 and 2:windows under Vscode compile debug C + +)
    3. Configuration of Launch.json and Tasks.json
    4. Configuration of the Vsc_tasks_java.bat
    5. Finished!

make sure that 1, 2 steps have been completed .

3. Configuration of the Launch.json
First open a folder, create a new Java file, write the code:

Note: The first line of code must be the name of the runtime to start class, with a format of two slash plus class name

Then press F5 to select C + + (GDB):

Replace the automatically generated Launch.json content with the contents and save:

{    "Version ":"0.2.0", "Configurations ":[ { "Name ":"JAVA Launch", "Type ":"Cppdbg", "Request ":"Launch", "launchoptiontype": "Local", "targetarchitecture": "x86", "program": "${file}" , "stopatentry": false, "CWD": "${workspaceroot}", "externalconsole": True, "  Prelaunchtask ": " cmd "}]}              

switch to the Debug interface, click Debug, note that this must be switched to the debug interface (because the first time to select a debug type), not directly press F5, after the first compilation run, the subsequent compilation run can be directly press F5:

This will pop up the message box and click on "Configure Task Program":

Here's a casual choice:

Then replace with the following code (note the comments, some can adjust themselves):

{    "version": "0.1.0",    "command": "cmd", "args": [ "/c", "start", "cmd","/c", "vsc_tasks_java.bat", "hide:true", //设为hide:true则会清除编译信息,否则将保留编译信息 "${fileDirname}", "${fileBasename}", "javac -Xlint:unchecked -encoding UTF-8 -g" //javac默认部分编译参数 ]}

configuration of the 4.vsc_tasks_java.bat
Save the following code as a vsc_tasks_java.bat file, and then copy it to the C:\Program files (x86) \java\jdk1.8.0_91\bin\ folder, and Note that it corresponds to the location of your own JDK , and make sure that the environment variable is set correctly

:::::::: Vscode TASKS JAVA by blackkitty::::::::@echo offSet jfdir=%2Set jf=%3Set jccmd=%~4Set jclassdir=%jfdir%\%jf%.classset/p jstartclass=< "%jfdir%\%jf% ">NULSet jstartclass=%jstartclass:~2%Echo.jfdir:%jfdir%ECHO.JF:%jf%Echo.jccmd:%jccmd%Echo.jclassdir:%jclassdir%Echo.jstartclass:%jstartclass%Echo.---------------------------Echo. CMD Execute:mkdir "%jclassdir% "IfNotExist "%jclassdir% "MkDir"%jclassdir% "Echo. CMD EXECUTE:%jccmd%-D "%jclassdir% ""%jfdir%\%jf% "(%jccmd%-D "%jclassdir% ""%jfdir%\%jf% ") | |set Jcerror=trueif "%jcerror%" EQU "true" (pause&goto:eof) pushd "%jclassdir%"  echo.-----------class-----------dir/b *.classecho.-----------class-----------echo. CMD Execute:java "%jstartclass%"echo.---------------------------If "%1" EQU "Hide:true" ( CLS) Java "%jstartclass%"pausegoto:eof::::::::vscode TASKS java by blackkitty:  :::: 

When you are finished, start debugging again, and the program is successfully compiled and run:
Do not display the compilation information:

To display the compilation information:

6. Finished!

Again: Vscode currently does not support debugging Java, this article is only the configuration using Vscode compiled run simple java,blackkitty does not write Java so this article is for entertainment

Java Basic Development Environment Vscode build Windows Vscode compile run simple Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.