I have inherited a codebase :)
Under src/test/java/ there\'s a file that I need to run (I need to run its public static void main(String[] args)
, not a
(...) I hope this is clearly explained.
Not bad but I can't reproduce. I created a project:
$ mvn archetype:generate -DgroupId=com.stackoverflow \ -DartifactId=Q4060613 \ -Dversion=1.0-SNAPSHOT \ -DarchetypeArtifactId=maven-archetype-quickstart
Then cd
ed into it and created a Dog
class (under src/main/java
):
$ cd Q4060613
$ cat > src/main/java/com/stackoverflow/Dog.java
package com.stackoverflow;
public class Dog {
public String bark() {
return "woof!";
}
}
and created a Demo
class (under src/test/java
):
$ cat > src/test/java/com/stackoverflow/Demo.java
package com.stackoverflow;
public class Demo {
public static void main(String[] args) {
System.out.println(new Dog().bark());
}
}
After compiling the source code, running the command you provided works as expected:
$ mvn test ... $ mvn exec:java -Dexec.mainClass="com.stackoverflow.Demo" -Dexec.classpathScope="test" [INFO] Scanning for projects... ... [INFO] --- exec-maven-plugin:1.2:java (default-cli) @ Q4060613 --- woof! [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ...
Something else must be wrong.