简体   繁体   中英

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

在此处输入图片说明

So I right click on sort folder, and try to add it to the Java build class path. 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 :

<?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. The "Source folder" literally means a Source Folder as designated in the Java Build Path, not just some folder that happens to contain source. The Name field wants the actual, proper in the "this is what a .java file in it would declare", qualified package name. 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.

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. If you have created it, just right click on the MergeSort.java file > Refactor > Move and select the new merge package under sort. This will move the file there and eclipse will show the package.

Alternatively if you haven't created the merge package yet, do the following: create a folder (not a package) Algorithms/src/sort/merge. Then find it in the eclipse tree > right click on it > Build Path > Use as Source Folder

Btw. you have only exclude on the sort package, because it is already on the build path (at least in the screenshot)

cheers

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

right button project-> properties->java Build path-> add a needed source to build path

在此处输入图片说明

Java package name convention defines that a period . marks a subfolder. So lorem.ipsum.dolor.sit.amet will create a folder structure like lorem/ipsum/dolor/sit/amet . Eclipse supports this format. So for you to create "subpackages", you need to create a package in the source folder named sort.merge in your case. 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. Maybe someone can shed light on that design decision?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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