I simply want to run a single .java file in my test-folder for debugging and testing. 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:
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:
main\\java\\MainSrc.java
run:
test
BUILD SUCCESSFUL (total time: 0 seconds)
test\\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):
<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. 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. 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).
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.