February 19th, 2020

Java on Visual Studio Code Update – February 2020

Xiaokai He
Senior Program Manager

Welcome back to the second update of Java on Visual Studio Code in 2020.

In this update, we will show you the new ways to manage your dependencies and configure your multiple JDK. You will learn the additional tools you can leverage for popular frameworks and runtimes. There’re also a few new code actions and improvements to checkout. On to the update.

Managing Dependencies

Whether your use any build tool or not, Java Dependency Viewer now provides you an easy way to deal with your dependencies.

Maven

If you’re using Maven, now it’s very convenient for you to add dependency for your Maven project through Java dependency explorer by clicking the +  button as below.

Image Kapture 2020 02 19 at 10 33 12

Other projects

If you’re not using any build tool like maven or gradle, and you want to reference binary jars in local file system, the experience is very similar to the maven experience above.

Image manage dependencies

Behind the scene, we’ve introduced a new setting java.project.referencedLibaries. Below are the details about how to customize this setting.

Include libraries

The libraries to reference is described using a set of glob patterns:

"java.project.referencedLibraries": [ 
    "library/**/*.jar", 
    "/home/username/lib/foo.jar" 
]

In this way, all .jar files in workspace’s library folder, and foo.jar in the specified absolute path is added to the project’s external dependencies.

The referenced libraries is then watched by VS Code, and the project will be refreshed once there’s change in these dependent files.

By default, VS Code will reference all jar files in workspace’s lib directory using glob lib/**/*.jar.

Exclude some libraries

If you want to exclude some libraries from the project, just expand java.project.referencedLibraries to full include-exclude-sources pattern and provide globs to exclude field:

"java.project.referencedLibraries": { 
    "include": [ 
        "library/**/*.jar", 
        "/home/username/lib/foo.jar" 
    ], 
    "exclude": [ 
        "library/sources/**" 
    ] 
}

In this way, any binary jar in library/sources folder is ignored from the project’s external dependencies.

Attach source jars

By default, a referenced {binary}.jar will try to search {binary}-sources.jar under the same directory, and attach it as source if one match is found.

If you want to manually specify a jar as source attachment, you can provide a key-value map in the sources field:

"java.project.referencedLibraries": { 
    "include": [ 
        "library/**/*.jar", 
        "/home/username/lib/foo.jar" 
    ], 
    "exclude": [ 
        "library/sources/**" 
    ], 
    "sources": { 
        "library/bar.jar": "library/sources/bar-src.jar" 
    } 
}

In this way, bar-src.jar is attached to bar.jar as its source.

Once external jar files are added, you can also see their file paths as description in Java Dependency Explorer.

Image dependency jar path

Image dependency jar path libraries

Image dependency jar path maven

Configure local JDK runtime

As Java evolves, lots of Java developers need to deal with multiple Java runtimes. Now we support a new preference mapping java.configuration.runtimes for Java execution environments. VS Code will detect the runtime required for your project and choose the appropriate one configured. See below as an example.

"java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/usr/local/jdk1.8.0_201"
        },
        {
            "name": "JavaSE-11",
            "path": "/usr/local/jdk-11.0.3",
            "sources" : "/usr/local/jdk-11.0.3/lib/src.zip",
            "javadoc" : "https://docs.oracle.com/en/java/javase/11/docs/api",
            "default":  true
        },
        {
            "name": "JavaSE-12",
            "path": "/usr/local/jdk-12.0.2"
        },
        {
            "name": "JavaSE-13",
            "path": "/usr/local/jdk-13"
        }
    ]

Runtime name must be one of: “J2SE-1.5”, “JavaSE-1.6”, “JavaSE-1.7”, “JavaSE-1.8”, “JavaSE-9”, “JavaSE-10”, “JavaSE-11”, “JavaSE-12”, “JavaSE-13”. We will update the list with each supported release of the JDK

Extensions for popular Java Frameworks and Runtimes

If you’re working with popular Java Frameworks such as Spring Boot and MicroProfile, Visual Studio Code has you covered as well. Below are some exciting new capabilities now available with those extensions

  1. Spring Boot Tools now reports connection failures in live hover.
  2. Newly released MicroProfile Extension Pack now includes MicroProfile Starter for you to quickly generate a MicroProfile Maven project along with development tools for runtimes such as Open Liberty and Quarkus with lots of new features.
  3. If you’re working with any Red Hat server and runtime products such as Wildfly or JBoss, checkout Server Connector which allows you to start, stop and deploy to any of them.

More enhancements

The latest updates also brings a lot of other enhancements for Java experience in Visual Studio Code.

  1. New code actions
    • Remove the final modifier.
    • Assign statement to new variable/field.
    • Remove redundant interfaces.
    • Add missing case labels in switch statements.
  2. Added java.import.gradle.offline.enabled preference.
  3. Expose full completion proposals to 3rd party extensions. This will enable other extensions such as IntelliCode to provide you better IntelliSense experience without impacting the completion performance.
  4. Java Dependency Viewer
    • add Collapse All  support
    • Support right click context menu for view nodes
  5. Maven
    • Support to debug favorite commands.
    • Add shortcut to view output when error occurs.
    • Support to browse for local Maven binary if not found.
  6.  Debugger
    • Provide context menu to continue/pause all/other threads.

Sign up

If you’d like to follow the latest of Java on VS Code, please provide your email with us using the form below. We will send out updates and tips every couple weeks and invite you to test our unreleased feature and provide feedback early on.

Try it out

Please don’t hesitate to give it a try! Your feedback and suggestions are very important to us and will help shape our product in future.

Author

Xiaokai He
Senior Program Manager

Xiaokai is the program manager working on Java developer tools and services at Microsoft. He’s currently focusing on making Visual Studio Code great for Java developers, as well as supporting Java in various of cloud services in Azure.

0 comments

Discussion are closed.