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

。_饼干妹妹 提交于 2019-12-22 10:48:08

问题


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>

回答1:


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.




回答2:


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




回答3:


Just create a package in your default source folder and name it sort.merge




回答4:


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?




回答5:


just right click on the folder src -> build path -> use the source folder is just this



来源:https://stackoverflow.com/questions/10910160/source-folder-is-not-on-the-java-build-class-path-creating-java-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!