Java 当项目名称与工作区名称相同时,Eclipse 中的“项目:由类路径引用的摆动不存在”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6484419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"The project: swing which is referenced by the classpath, does not exist" in Eclipse when project name is the same as workspace name
提问by aquero
I am new to swing development using eclipse but I have been using eclipse for my java code development for more than a year. Today when I wrote a sample swing class got a curious error from eclipse.
我是使用 eclipse 进行 Swing 开发的新手,但我已经使用 eclipse 进行 java 代码开发一年多了。今天,当我编写一个示例 Swing 类时,Eclipse 出现了一个奇怪的错误。
I created a workspace swing , and created a new project in the same name as the workspace. Then wrote a sample class inside the project, please find the code below.
我创建了一个工作区 swing ,并创建了一个与工作区同名的新项目。然后在项目内部写了一个示例类,请在下面找到代码。
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class SwingDemo {
public SwingDemo() {
// TODO Auto-generated constructor stub
JFrame jFrame = new JFrame("A sample swing application");
jFrame.setSize(275, 100);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel jLabel = new JLabel("Welcome to swing!!!!");
jFrame.add(jLabel);
jFrame.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new SwingDemo();
}
});
}
}
When I tried to execute it in eclipse ,resulted in the below error
当我尝试在 eclipse 中执行它时,导致以下错误
The project: swing which is referenced by the classpath, does not exist.
类路径引用的项目:swing 不存在。
The same code was executed fine, when the project name and workspace name were differrent.
当项目名称和工作区名称不同时,相同的代码执行得很好。
I am just curious, what caused this error. Please help
我只是好奇,是什么导致了这个错误。请帮忙
回答by jzilla
In the project properties, in the "Java Build Path" section and the "Projects" tab, is a list of other projects that this project depends on. When you view this, you should see at least one red marker in the list of projects, on the line that lists the "xxxxxx" project. If you don't really need that project, then select that line and click "Remove" and "OK". If that just creates other problems, then you'll have to figure out what was supposed to be in that missing project and get it created. Perhaps there's another project in your workspace with a slightly different name that represents what your project needs?
在项目属性的“Java 构建路径”部分和“项目”选项卡中,是该项目所依赖的其他项目的列表。当您查看此内容时,您应该在项目列表中看到至少一个红色标记,在列出“xxxxxx”项目的行上。如果您真的不需要该项目,请选择该行并单击“删除”和“确定”。如果这只是造成其他问题,那么您必须弄清楚该丢失的项目中应该包含什么并创建它。也许您的工作区中有另一个项目名称略有不同,代表您的项目需要什么?
回答by Deepak
I have faced the same problem as you did. Do not give the Project and Workspace the same name. If this is the case then give different names and rebuild it. It will work.
我遇到了和你一样的问题。 不要给项目和工作区同名。如果是这种情况,则给出不同的名称并重建它。它会起作用。
回答by Pavan
One reason for the error might be that you have used same name for both Workspace and Project.
错误的原因之一可能是您对工作区和项目使用了相同的名称。
Changing it and rebuilding should resolve the issue in that case.
在这种情况下,更改它并重建应该可以解决问题。
回答by Lodlaiden
Verify your root .classpath file does not have invalid entries. These did not show up in the Preferences -> Build -> Classpath
验证您的根 .classpath 文件没有无效条目。这些没有出现在 Preferences -> Build -> Classpath
</classpathentry>
<classpathentry kind="src" path="/src"/>
<classpathentry kind="lib" path="log4j.xml"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>