[英]Cannot “Run File” from src\test folder -> main class not found or could not be loaded
I simply want to run a single .java file in my test-folder for debugging and testing. 我只想在我的测试文件夹中运行一个.java文件进行调试和测试。 If I run it in my main folder, all is fine, If I run it in my test folder, i get an error: 如果我在我的主文件夹中运行它,一切都很好,如果我在我的测试文件夹中运行它,我收到一个错误:
My project sturcture: 我的项目结构:
src
|_____ main
|_____ java -> MainSrc.java
|_____ test
|_____ java -> MainTest.java
MainSrc / MainTest.java contains: MainSrc / MainTest.java包含:
public class MainSrc / MainTest
{
public static void main(String[] args)
{
System.out.println("test");
}
}
Now if i right-click and hit "run file" on both in netbeans: 现在,如果我右键单击并在netbeans中同时点击“运行文件”:
main\\java\\MainSrc.java 主\\ java的\\ MainSrc.java
run:
test
BUILD SUCCESSFUL (total time: 0 seconds)
test\\java\\MainTest.java 测试\\ java的\\ MainTest.java
cd C:\Java\MainTest; "JAVA_HOME=C:\\Program Files (x86)\\Java\\jdk1.7.0_02"
"\"C:\\Program Files\\NetBeans 7.2\\java\\maven\\bin\\mvn.bat\""
"-Dexec.args=-classpath %classpath Test"
"-Dexec.executable=C:\\Program Files (x86)\\Java\\jdk1.7.0_02\\bin\\java.exe"
-Dexec.classpathScope=test --offline --errors process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec
Error stacktraces are turned on.
Scanning for projects...
------------------------------------------------------------------------
Building Test 1.0
------------------------------------------------------------------------
[resources:resources]
[debug] execute contextualize
Using 'windows-1252' encoding to copy filtered resources.
Copying 0 resource
[compiler:compile]
Nothing to compile - all classes are up to date
[exec:exec]
Error: could not find or load main class MainTest
------------------------------------------------------------------------
BUILD FAILURE
my actions is (also tried classPathScope=test): 我的动作是(也试过classPathScope = test):
<action>
<actionName>run</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath MainTest</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>${classPathScope}</exec.classpathScope>
<exec.workingdir>D:\Dropbox\Java\Test Automation Selenium</exec.workingdir>
</properties>
</action>
I am not a pro in Java, most i googled together but I could not find a solution for this. 我不是Java的专业人士,大多数我用Google搜索,但我找不到解决方案。 I also don't understand why it does not work. 我也不明白为什么它不起作用。 I tried to access the test package from my default package, but ofc that was not possible... 我试图从我的默认包中访问测试包,但是这是不可能的...
Help please? 请帮助? :) Thank you :) 谢谢
This sounds like the magic "no main class found" exception (sorry if not!). 这听起来像是一个神奇的“没有发现主要类别”的例外(如果不是,请对不起!)。
I've seen this quite some times on the NB users mailinglist and once per year I also ran into this magic exception. 我在NB用户邮件列表上已经看过很多次了,每年我也遇到过这个神奇的例外。 I gathered the solutions that I found and that usually helped me fixing these kind of exception/error (the listing is based on the times of NB 6.8 but might still hold). 我收集了我找到的解决方案 ,这通常帮助我修复了这种异常/错误(列表基于NB 6.8的时间,但可能仍然存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.