Java Eclipse -- Testng 引用不存在的项目 XXX,启动配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23116556/
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
Eclipse -- Testng references non-existing project XXX, launch configuration
提问by J-Dizzle
When trying to run a test as a TestNG suite, I would get a very cryptic error message saying that TestNG can't launch because it references a non-existant project. I think my project does exist, I see it in the package explorer!
当尝试将测试作为 TestNG 套件运行时,我会收到一条非常神秘的错误消息,指出 TestNG 无法启动,因为它引用了一个不存在的项目。我认为我的项目确实存在,我在包浏览器中看到了它!
采纳答案by J-Dizzle
It turns out you just have to make sure your project is a Java Project, and not a Simple project. Check that the navigatorshows a little blue 'J'associated with the folder. If not, then you have created a Simple project.
事实证明,您只需要确保您的项目是 Java Project而不是 Simple 项目。检查导航器是否显示与文件夹关联的蓝色小“J”。如果没有,那么您已经创建了一个 Simple 项目。
"It would appear that the project you created is not Java project.
“看起来您创建的项目不是 Java 项目。
Eclipse auto-builds the .java file to .class files for all .java files contained in a Java project.
Eclipse 自动将 .java 文件构建为 Java 项目中包含的所有 .java 文件的 .class 文件。
To create a Java project File>New>Project>Java Project Give the project a name. Click Finish"
创建 Java 项目 File>New>Project>Java Project 为项目命名。点击完成”
Found this answer hidden deep in this source.
发现这个答案隐藏在这个来源的深处。
In eclipse you should be using Navigator and not Package explorer, as navigator is browsing the actual filesystem, where package explorer is loading certain things only. In the future hopefully people can find the solution more easily.
在 Eclipse 中,您应该使用 Navigator 而不是 Package explorer,因为 navigator 正在浏览实际的文件系统,其中 package explorer 只加载某些东西。希望将来人们可以更轻松地找到解决方案。
回答by yousafsajjad
If its an existing project, you must have classpath and project file in project root folder to make it java project.
如果它是现有项目,则必须在项目根文件夹中具有类路径和项目文件才能使其成为 java 项目。
Sample:
样本:
<!--classpath -->
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
<!-- .project -->
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>testProject</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
回答by Hridaynath
I have faced the same problem while I was working with raspbian OS for raspberry pi. The problem was the java project was referencing to one of my previous project.
我在为 raspberry pi 使用 raspbian OS 时遇到了同样的问题。问题是 java 项目引用了我以前的项目之一。
I resolved this problem by doing following steps.
我通过执行以下步骤解决了这个问题。
- Go to Project->properties
- In properties window's left pane select "Run/Debug Settings".
- Select "Configure" and click "edit"
- In tab "Main" replace Project to your current project.
- Select "Main class" by clicking on search button(it will be your class name).
- Now hit OK.
- 转到项目-> 属性
- 在属性窗口的左窗格中选择“运行/调试设置”。
- 选择“配置”并点击“编辑”
- 在“Main”选项卡中,将 Project 替换为您当前的项目。
- 单击搜索按钮选择“主班级”(它将是您的班级名称)。
- 现在点击确定。
回答by Philip Kirkbride
In my case the run shortcut was referencing an old project.
在我的情况下,运行快捷方式引用了一个旧项目。
Simply right clicking on the folder of the project I was trying to run and selecting my java class fixed the problem.
只需右键单击我尝试运行的项目文件夹并选择我的 java 类即可解决问题。
After that pressing the run button started working again.
之后按下运行按钮再次开始工作。
回答by John Czukkermann
I know this is an old post, but I hit this recently when I moved to using a MacBook Pro.
我知道这是一个旧帖子,但我最近在使用 MacBook Pro 时遇到了这个问题。
When I created a new Eclipse workspace and loaded all of my projects from the SCM, I got these Ant failures due to referencing an non-existing project.
当我创建一个新的 Eclipse 工作区并从 SCM 加载我的所有项目时,由于引用了一个不存在的项目,我遇到了这些 Ant 故障。
The solution was not easy to discover, but the solution is simple: Change your Ant run configuration's JRE to run in the same JRE as the workspace.
解决方案不容易发现,但解决方案很简单:更改您的 Ant 运行配置的 JRE,使其在与工作区相同的 JRE 中运行。
You DO NOT need to change your build projects to Java projects.
您不需要将构建项目更改为 Java 项目。
回答by Sireesh Yarlagadda
Solved in a different way for the same issue.
以不同的方式解决相同的问题。
1) Go to Project->properties.
1) 转到项目-> 属性。
2) In properties window's left pane select "Project Facets".
2) 在属性窗口的左窗格中选择“Project Facets”。
3) Then click on "Convert to faceted form"
3)然后单击“转换为多面形式”
4) Then choose your server and JDK version.
4)然后选择您的服务器和JDK版本。
Apply and Close.
应用并关闭。
Note: Verify the project and the default IDE JRE is same version.
注意:验证项目和默认 IDE JRE 是相同的版本。
回答by BILAL YILDIZ
It doesn't have to be a Java Project, it could be a Maven one as well. There could be a reference problem with the oldest version of the project. Please try deleting the oldest version from your Eclipse workspace, and then change your reference point.
它不一定是 Java 项目,也可以是 Maven 项目。项目的最旧版本可能存在参考问题。请尝试从您的 Eclipse 工作区中删除最旧的版本,然后更改您的参考点。
回答by Andrew Norman
This issue will manifest for you if you have a test class in a current project that you are trying to run that matches a test class from the project that you either closed or deleted and had previously run unit tests against.
如果您正在尝试运行的当前项目中有一个测试类,该类与您关闭或删除的项目中的测试类相匹配,并且之前已针对该项目运行过单元测试,则此问题将为您显现。
Chances are you have a test case from this deleted / missing or closed project. Eclipse will hide the launch configurations of deleted and closed projects but still attempts to use them when you do the 'right click on class' -> 'run-as' way to invoke a unit test.
您可能从这个已删除/丢失或已关闭的项目中获得了一个测试用例。Eclipse 将隐藏已删除和已关闭项目的启动配置,但在您执行“右键单击类”->“run-as”方式来调用单元测试时仍会尝试使用它们。
The solution here is to unhide the problem launch configuration so you can delete it or modify it to conform to the current project.
这里的解决方案是取消隐藏问题启动配置,以便您可以将其删除或修改以符合当前项目。
Unhide the launch configurations of deleted and closed projects:
取消隐藏已删除和已关闭项目的启动配置:
This is done via the dropdown menu path -> Eclipse -> Preferences -> "Run/Debug" -> Launching -> "Launch Configurations" In the "Launch Configurations" screen find the "launch configuration filters" section and uncheck the top 2 checkboxes: - "Filter configurations in closed projects" - "Filter configurations in deleted or missing projects" click the "Apply and close" button and close the popup screen.
这是通过下拉菜单路径 -> Eclipse -> Preferences -> "Run/Debug" -> Launching -> "Launch Configurations" 在 "Launch Configurations" 屏幕中找到 "launch configuration filters" 部分并取消选中前 2 个复选框: - “在关闭的项目中过滤配置” - “在已删除或丢失的项目中过滤配置”单击“应用并关闭”按钮并关闭弹出屏幕。
Edit / delete the problem configuration:
编辑/删除问题配置:
open the Run -> "Run configurations" from the dropdown menu. On the left find and select the (no longer hidden) run configuration. In this configuration you can either update the project references to the current project or you can delete the configuration altogether. If you delete the run configuration eclipse will create a new one from scratch with the correct project settings when you attempt to "run as" on the current class.
从下拉菜单中打开“运行”->“运行配置”。在左侧找到并选择(不再隐藏)运行配置。在此配置中,您可以更新对当前项目的项目引用,也可以完全删除配置。如果您删除运行配置,当您尝试在当前类上“运行身份”时,eclipse 将使用正确的项目设置从头开始创建一个新配置。
回答by serv-inc
In my case, the error occurred in a Scala project. It had installed the eclipse plugin, but it had not been used yet.
就我而言,错误发生在Scala 项目中。它已经安装了 eclipse 插件,但尚未使用。
Diagnostics: If all goes well, the project has a blue Sfor scala project. If not, it has a yellow PC mouse (for whatever that means).
诊断:如果一切顺利,scala 项目会有一个蓝色的S。如果没有,它有一个黄色的 PC 鼠标(不管这意味着什么)。
To fix, you need to
要修复,您需要
sbt eclipse
on the command-line. Eclipse recognizes it as Scala project at the latest on restart.
在命令行上。Eclipse 最迟在重新启动时将其识别为 Scala 项目。