我只想在我的测试文件夹中运行一个 .java 文件以进行调试和测试。如果我在我的主文件夹中运行它,一切都很好,如果我在我的测试文件夹中运行它,我得到一个错误:
我的项目结构:
src
|_____ main
|_____ java -> MainSrc.java
|_____ test
|_____ java -> MainTest.java
MainSrc / MainTest.java 包含:
public class MainSrc / MainTest
{
public static void main(String[] args)
{
System.out.println("test");
}
}
现在,如果我在 netbeans 中右键单击并点击“运行文件”:
主\java\MainSrc.java
run:
test
BUILD SUCCESSFUL (total time: 0 seconds)
测试\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
我的操作是(也尝试过 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>
我不是 Java 专业人士,我大部分时间都在谷歌上搜索,但我找不到解决方案。我也不明白为什么它不起作用。我试图从我的默认包中访问测试包,但那是不可能的...
请帮忙?:) 谢谢