简体   繁体   English

如何在 Visual Studio Code 的 java 项目中制作包

[英]How to make packages in java project in visual Studio Code

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.我是 java 的初学者,因此不知道 maven 或 boot Spring。我已经尝试过 Eclipse 和 IntelliJ,想试试 Visual Studio Code。 I can make an Eclipse Project in VS Code but I cannot find any option there.我可以在 VS Code 中创建一个 Eclipse 项目,但我在那里找不到任何选项。 I have installed the Java Extension for Visual Studio Code.我已经为 Visual Studio Code 安装了 Java 扩展。 Any Help would be appreciated.任何帮助,将不胜感激。 I am using the latest Visual Studio Code March 2020 .我使用的是最新的Visual Studio Code March 2020 Thanks in advance!提前致谢!

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.我和你有同样的情况,我想在 VS 代码中自己创建包,只需按照以下步骤操作:打开你的 VS 代码。

Step 1: Click on "Explorer", should be at top-left corner.第1步:点击“资源管理器”,应该在左上角。 在此处输入图像描述

Step 2: Click on "New Folder"第二步:点击“新建文件夹”

在此处输入图像描述

Step 3: Enter the name of your package here.第 3 步:在此处输入您的 package 的名称。

在此处输入图像描述

Step 4: Drag and drop the your classes in that package.第 4 步:将您的课程拖放到 package 中。

在此处输入图像描述

You are all set now!你现在都准备好了! Good luck!祝你好运!

Image showing where to Right Click: create a Java Package in VS Code显示右键单击位置的图像:在 VS 代码中创建 Java Package

Inside the Java Projects tab, right click on the project.在 Java 项目选项卡中,右键单击项目。 You can then choose to create a new Java Class or Package.然后您可以选择创建一个新的 Java Class 或 Package。

I would recommend checking out Java Env Setup for VS Code.我建议查看VS Code 的 Java 环境设置。

and secondly:其次:

A package is a path of subdirectories. package 是子目录的路径。 Say your java sources are in (subdirectory of) a > directory src.假设您的 java 源位于(子目录)a > 目录 src 中。 All sources immediately under src have the "default" package = no package > declaration. src 下的所有源都具有“默认” package = no package > 声明。

In src/com/java/learn (4 nested directories) the package com.java.learn;在 src/com/java/learn(4 个嵌套目录)中,package com.java.learn; is expected for > java sources.预计用于 > java 源。

In your case create a path of 3 directories: com, java, and learn the latter containing > your java source.在您的情况下,创建 3 个目录的路径:com、java,并了解后者包含 > 您的 java 源。

recycled from here: How to Start a Java Project with package declaration on Visual Studio Code?从这里回收: 如何在 Visual Studio Code 上使用 package 声明启动 Java 项目?

Just go to explorer and click on new folder.只需 go 到资源管理器并单击新文件夹。 And then name the folder your package name.然后将文件夹命名为 package 名称。 Drag and drop the classes you want in that package将所需的类拖放到 package 中

Even I was in the same situation so I researched and got some results.即使我处于同样的情况,所以我进行了研究并得到了一些结果。 Make sure you have JDK and JVM in your machine确保你的机器上有 JDK 和 JVM

You need to install Extension pack for java (from Microsoft) which is available by searching in extensions in Visual Studio您需要安装 java(来自 Microsoft)的扩展包,可通过在 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.确保安装与该扩展相关的所有包,例如 Maven 用于 Java,调试器用于 java,项目管理器用于 Java 和测试运行器用于 java 所有这些都来自 Microsoft。 After installing these you can run your java files.安装这些后,您可以运行 java 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM