9

I am a beginner in java, and hence do not know maven or boot Spring. I have tried Eclipse and IntelliJ, and wanted to try Visual Studio Code. I can make an Eclipse Project in VS Code but I cannot find any option there. I have installed the Java Extension for Visual Studio Code. Any Help would be appreciated. I am using the latest Visual Studio Code March 2020. Thanks in advance!

6 Answers 6

16

Image showing where to Right Click: create a Java Package in VS Code

Inside the Java Projects tab, right click on the project. You can then choose to create a new Java Class or Package.

Sign up to request clarification or add additional context in comments.

3 Comments

This is right answer. For those who installed the extension but still can't find where to find the shortcut.
@Sophiecai What extension is it that you mean?
@NoName123 I think it's about Extension Pack for Java
9

I had the same situation as you, I figured creating packages on my own in VS code, Just follow these steps: Open up your VS code.

Step 1: Click on "Explorer" , should be at top-left corner. enter image description here

Step 2: Click on "New Folder"

enter image description here

Step 3: Enter the name of your package here.

enter image description here

Step 4: Drag and drop the your classes in that package.

enter image description here

You are all set now! Good luck!

Comments

1

I would recommend checking out Java Env Setup for VS Code.

and secondly:

A package is a path of subdirectories. Say your java sources are in (subdirectory of) a > directory src. All sources immediately under src have the "default" package = no package > declaration.

In src/com/java/learn (4 nested directories) the package com.java.learn; is expected for > java sources.

In your case create a path of 3 directories: com, java, and learn the latter containing > your java source.

recycled from here: How to Start a Java Project with package declaration on Visual Studio Code?

Comments

0

Just go to explorer and click on new folder. And then name the folder your package name. Drag and drop the classes you want in that package

Comments

0

Even I was in the same situation so I researched and got some results. Make sure you have JDK and JVM in your machine

You need to install Extension pack for java (from Microsoft) which is available by searching in extensions in Visual Studio

Make sure you install all the packages related to that extension such Maven for Java, Debugger for java, Project Manager for Java and Test runner for java all these are from Microsoft. After installing these you can run your java files.

Comments

-1

To create a new package in Visual Studio Code for a Maven project, follow these steps:

Right-click on the location where you want to create the package (e.g., inside the src/test/java folder). Select New Folder. Name the folder with your desired package name, appending \package at the end. For example, if you want to create a package named package23, name the folder package23\package.

This will correctly set up the package structure in your Maven project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.