Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@
[![License](https://img.shields.io/github/license/oracle/javavscode?style=for-the-badge&logo=apache)](https://github.com/oracle/javavscode/blob/main/LICENSE.txt)

Java Platform extension from Oracle brings full featured development support (edit-compile-debug & test cycle) to VS Code. It also offers support for Maven and Gradle projects. Applications using JDK 8 and above are supported.


## Getting Started
1. Setting up the JDK
1. See the [VS Code Tips](https://github.com/oracle/javavscode/wiki/VSCode-Tips) wiki for a quick primer on getting started with VS Code.
2. Setting up the JDK
- If no JDK is present in your system then the extension can set things up for you. For more details refer to [JDK Downloader](#jdk-downloader) section.
- Set the JDK in the `View | Command Palette | Preferences: Open User Settings | Jdk: Jdkhome` setting to point to the JDK that the Language Server will run on and also by default use for running and compiling projects.
- Set the VS Code `Settings | Jdk: Jdkhome` setting to point to the JDK that the Language Server will run on and also by default use for running and compiling projects.
- The extension requires JDK 17 or newer to run.
- Optionally, set a different JDK to compile and run projects in the `View | Command Palette | Preferences: Open User Settings | Jdk › Project: Jdkhome` setting.
- Optionally, set a different JDK to compile and run projects in the `Settings | Jdk › Project: Jdkhome` setting.
- By default, the __jdk.jdkhome__ setting is used.
- Projects can run on JDK 8 and above.
- For more information, see the section [Selecting the JDK](#selecting-the-jdk).
4. Use any one of the following ways to start coding, compiling and debugging in Java.
- Simply create a new Java class with `public static void main(String[] args)` method.
3. Use any one of the following ways to start coding, compiling and debugging in Java.
- Simply create a new Java class with `main` method.
- Use the __Java: New File from Template...__ command to create a new Java file.
- Use the __Java: New Project...__ command to create a new project.
- Open the folder with existing __Maven__ or __Gradle__ project files (_pom.xml_ or _build.gradle, gradle.properties_).
Expand Down Expand Up @@ -67,38 +70,40 @@ Project Explorer provides an overview of logical project structure, groups sourc

## Interactive Java Notebooks
### Introduction
* Experience interactive coding with Java notebooks.
Use the __Java: Create New Notebook...__ command to create a new Java notebook(`.ijnb` file)
![Java Notebook](vscode/images/java_notebook.gif)
* Jupyter-style notebooks let you combine Java code snippets with markdown-formatted text cells.
* Run individual code cells or execute the entire notebook.
* Save outputs alongside code cells.
* Sharing notebooks
* Experience interactive coding with Java notebooks. See the [Using Interactive Java Notebooks](https://github.com/oracle/javavscode/wiki/Interactive-Java-Notebooks) wiki for guidance and tutorials on using notebooks.
* Use the __Java: Create New Notebook...__ command to create a new Java notebook(`.ijnb` file)<br/>
![Java Notebook](vscode/images/java_notebook.gif)
* Add code snippets with `+ Code` button and document with markdown cells with `+ Markdown`.
* Double click on a cell to edit and hit `Esc` when done.
* Jupyter-style notebooks let you combine Java code snippets with markdown-formatted text cells.
* Run individual code cells or execute the entire notebook.
* Can save outputs alongside code cells.
* Sharing notebooks
* Share as `.ijnb` files for use with Oracle Java extension.
* Rename with `.ipynb` for viewing in other IDEs Jupyter etc.
* Download the [sample notebooks](https://github.com/oracle/javavscode/blob/main/samples/notebooks) and open in VSCode to get started.
* Download the [sample notebooks](https://github.com/oracle/javavscode/blob/main/samples/notebooks) and open in VS Code to get started.

### Java Notebooks for Java Projects
* Document Java projects with interactive Java notebooks.
* Open/Create a Java notebook in your workspace folder loaded with classes from your project.
* Document Java projects with interactive Java notebooks.
* Open/Create a Java notebook in your workspace folder loaded with classes from your project.<br/>
![Java Notebook For Project](vscode/images/project_notebook.gif)
* Use `Project Context` options incase you want to change to a different project context .
![Switch Project Context](vscode/images/project_context.png)
* Provide code snippets, markdown explanations, and expected outputs.
* Use `Project Context` options in case you want to change to a different project context.<br/>
![Switch Project Context](vscode/images/project_context.png)
* Provide code snippets, markdown explanations, and expected outputs.

### Notebook Configurations
* Following configuration settings are available
* Following configuration settings are available
* `jdk.notebook.classpath`
* `jdk.notebook.modulepath`
* `jdk.notebook.addmodules`
* `jdk.notebook.enablepreview`
* `jdk.notebook.implicitimports`
* Note : These settings *override* any settings inferred from project context 
* Note: These settings *override* any settings inferred from project context 

## JShell
* Use the __Java: Open JShell...__ command to open JShell .
* Project classes from currently open project are automatically loaded.
![JShell](vscode/images/jshell.gif)
* Use the __Java: Open JShell...__ command to open JShell.
* Project classes from currently open project are automatically loaded.<br/>
![JShell](vscode/images/jshell.gif)

## Debugger and Launch Configurations
Language Server __Java+ ...__ launch configuration supports debugging and running Java applications using JDK11 or newer.
Expand Down Expand Up @@ -129,7 +134,7 @@ When using preview features use the quick fix action option to easily enable the
![Enable Preview](vscode/images/enable_preview.gif)
## Supported Refactorings

Class level refactorings as well as variable refactorings are supported in VSCode via Oracle Java Platform extension. See following screenshots:
Class level refactorings as well as variable refactorings are supported in VS Code via the Oracle Java Platform extension. See the following screenshots:

### Source Action ... context menu
![Class Source Actions](vscode/images/Source_actions.png)
Expand Down Expand Up @@ -176,36 +181,36 @@ Move members refactoring provides dedicated form as well.
## Formatter Preferences
Easily update default formatter preferences by adjusting a simple configuration option to tailor settings according to specific needs.

Go to VSCode `View | Command Palette | Preferences:Open User Settings | Extensions | Java` and set `Jdk › Format: Settings Path:` option to the formatter preferences file.
Open VS Code `Settings | Extensions | Java` and set `Jdk › Format: Settings Path:` option to the formatter preferences file.

Please refer to [Java formatting preferences](https://github.com/oracle/javavscode/wiki/Java-formatting-preferences) wiki for more info.

## Hints Preferences
Easily update default hint preferences by adjusting a simple configuration option to tailor hint preferences to specific needs.

Go to VSCode `View | Command Palette | Preferences:Open User Settings | Extensions | Java` and set `Jdk › Hints: Preferences:` option to the xml hint preferences file.
Open VS Code `Settings | Extensions | Java` and set `Jdk › Hints: Preferences:` option to the xml hint preferences file.

## Organize Imports
Out of the box support for organizing imports in Java sources is available. It removes unused imports, groups imports by packages and updates your imports whenever a file is saved. In addition to the defaults, there is a rich set of configuration options.

Go to VSCode `View | Command Palette | Preferences:Open User Settings | Extensions | Java` and search for _Jdk_ to set `Jdk > Java > Imports:` options:
Open VS Code `Settings | Extensions | Java` and search for _Jdk_ to set `Jdk Java Imports:` options:
* `Count For Using Star Import` - Class count to use a star-import, 999 is the default value
* `Count For Using Static Star Import` - Members count to use a static star-import, 999 is the default value
* `Groups` - Groups of import statements (specified by their package prefixes) and their sorting order. Import statements within a group are ordered alphabetically

And `View | Command Palette | Preferences:Open User Settings | Extensions > Java > On Save: Organize Imports` - Enable organize imports action on a document save
The `Jdk › Java › On Save: Organize Imports` setting in VS Code `Settings | Extensions | Java` enables the **Organize Imports** action to run when saving a document.

## JavaDoc smart editing
When adding JavaDoc to code Oracle Java Platform extension assists by suggesting to insert preformatted and prepopulated JavaDoc comment. Type `/**` above method signature and IDE offers to complete the JavaDoc. The action creates JavaDoc comment with all arguments prepared.
When adding JavaDoc to code Oracle Java extension assists by suggesting to insert preformatted and prepopulated JavaDoc comment. Type `/**` above method signature and IDE offers to complete the JavaDoc. The action creates JavaDoc comment with all arguments prepared.
![JavaDoc Completion](vscode/images/javadoc.png)

## Test Explorer
Oracle Java Platform extension provides Test Explorer view which allows to run all tests in a project, examine the results, go to source code and run particular test.
Oracle Java extension provides Test Explorer view which allows to run all tests in a project, examine the results, go to source code and run particular test.
![Test Explorer](vscode/images/Test_explorer.png)

### Localization support
Oracle Java Platform extension provides localization support for _Japanese_ and _Simplified Chinese_.
To switch language `Go to command Palette->Configure display language` select `ja` for _Japanese_ or `zh-cn` for _Simplified Chinese_
Oracle Java extension provides localization support for _Japanese_ and _Simplified Chinese_.
Use the `View | Command Palette | Configure Display Language` command to select `ja` for _Japanese_ or `zh-cn` for _Simplified Chinese_


![Localization.gif](vscode/images/Localization.gif)
Expand All @@ -222,9 +227,8 @@ As soon as one of the settings is changed, the Language Server is restarted.

## How to use JDK early access builds
This setup makes it easier to experiment with early access JDK builds. Follow these steps to enable the use of an early access JDK:
Step-1: Navigate to `View | Command Palette | Preferences:Open User Settings | Jdk > Advanced > Disable: Nbjavac` and enable the checkbox.

Step-2: Set the JDK in `View | Command Palette | Preferences:Open User Settings (JSON) ...` by updating the __jdk.jdkhome__ setting to point to the early access JDK path.
1. Open VS Code `Settings | Jdk › Advanced › Disable: Nbjavac` and enable the checkbox.
2. Set `Settings | Jdk: Jdkhome` to point to the home-folder path of the early access JDK.

## Troubleshooting
If your extension is not starting and throwing some error like no JDK found even if you have a working JDK installed in your machine, then you can try deleting cache for the workspace using `View | Command Palette | Delete oracle java extension cache for this workspace`.
Expand Down
Binary file modified vscode/images/enable_preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vscode/images/java_notebook.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vscode/images/jshell.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vscode/images/project_notebook.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.