简体   繁体   English

源文件夹不在 Java 构建类路径上,创建 Java 包

[英]Source folder is not on the Java build class path, creating Java package

I am trying to create a package merge under sort, but it it saying that:我正在尝试在排序下创建一个包合并,但它说:

Source folder is not on the Java build class path源文件夹不在 Java 构建类路径上

在此处输入图片说明

So I right click on sort folder, and try to add it to the Java build class path.所以我右键单击 sort 文件夹,并尝试将其添加到 Java 构建类路径中。 But only option there is exclude, so it means it should already be included to class path.但唯一的选项是排除,所以这意味着它应该已经包含在类路径中。在此处输入图片说明

So how can I create the package under sort?那么如何在排序下创建包?

EDIT:编辑:

added .classpath :添加 .classpath :

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Do it from the context menu of the "src" folder itself.从“src”文件夹本身的上下文菜单中执行此操作。 The "Source folder" literally means a Source Folder as designated in the Java Build Path, not just some folder that happens to contain source. “源文件夹”字面意思是在 Java 构建路径中指定的源文件夹,而不仅仅是某个恰好包含源的文件夹。 The Name field wants the actual, proper in the "this is what a .java file in it would declare", qualified package name. Name 字段需要实际的、正确的“这是其中的 .java 文件将声明的内容”,限定包名称。 If you just wanted to create a new folder in there to then make some new .java files, you can just use the New Folder wizard.如果您只想在其中创建一个新文件夹,然后创建一些新的 .java 文件,您可以使用新建文件夹向导。

EDIT: Also, keep in mind that the Package Presentation setting (set from the view's local menu--the upside down triangle) might be different between the Project and Package Explorer views.编辑:另外,请记住,项目和包资源管理器视图之间的包展示设置(从视图的本地菜单设置 - 倒三角形)可能不同。 Adjust as you see fit if things look the opposite of how you'd like.如果事情看起来与您想要的相反,请根据您认为合适的方式进行调整。

只需右键单击文件夹src -> 构建路径 -> 使用源文件夹就是这样

Have you already created the merge package.您是否已经创建了合并包。 Maybe you have the option of eclipse not to show empty packages on.也许您可以选择 eclipse 不显示空包。 If you have created it, just right click on the MergeSort.java file > Refactor > Move and select the new merge package under sort.如果已经创建,只需右键单击 MergeSort.java 文件 > Refactor > Move 并选择 sort 下的新合并包。 This will move the file there and eclipse will show the package.这会将文件移动到那里,eclipse 将显示该包。

Alternatively if you haven't created the merge package yet, do the following: create a folder (not a package) Algorithms/src/sort/merge.或者,如果您尚未创建合并包,请执行以下操作:创建一个文件夹(不是包)Algorithms/src/sort/merge。 Then find it in the eclipse tree > right click on it > Build Path > Use as Source Folder然后在eclipse树中找到它>右键单击它>构建路径>用作源文件夹

Btw.顺便提一句。 you have only exclude on the sort package, because it is already on the build path (at least in the screenshot)您只排除了 sort 包,因为它已经在构建路径上(至少在屏幕截图中)

cheers干杯

只需在您的默认源文件夹中创建一个包并将其命名为sort.merge

right button project-> properties->java Build path-> add a needed source to build path右键项目->属性->java构建路径->添加需要的源构建路径

在此处输入图片说明

Java package name convention defines that a period . Java 包命名约定定义了一个句点. marks a subfolder.标记一个子文件夹。 So lorem.ipsum.dolor.sit.amet will create a folder structure like lorem/ipsum/dolor/sit/amet .所以lorem.ipsum.dolor.sit.amet将创建一个文件夹结构,如lorem/ipsum/dolor/sit/amet Eclipse supports this format. Eclipse 支持这种格式。 So for you to create "subpackages", you need to create a package in the source folder named sort.merge in your case.因此,要创建“子包”,您需要在源文件夹中创建一个名为sort.merge的包。 This will automatically create the desired folder structure.这将自动创建所需的文件夹结构。

But you're right, I never understood why Eclipse does not show the package structure in a way that reflects the underlying folder structure.但是您说得对,我一直不明白为什么 Eclipse 不以反映底层文件夹结构的方式显示包结构。 Maybe someone can shed light on that design decision?也许有人可以阐明该设计决策?

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

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