From Maven, how do I run a class that lives under src/test/java?

前端 未结 4 1927
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 18:36

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

4条回答
  •  鱼传尺愫
    2020-12-30 18:59

    I faced the same problem and figured it out.

    Shortly speaking, the class must be compiled before exec:java goal. (It surely works without test-compile phase if the class is already compiled by other user action. Note that Pascal Thivent, in his answer, invoked mvn test before exec:java.)

    $ mvn -Dexec.mainClass=... -Dexec.classpathScope=test test-compile exec:java
    

    You can prove it for yourself if you want to see the ClassNotFoundException again.

    $ mvn -Dexec.mainClass=... -Dexec.classpathScope=test clean exec:java
    

提交回复
热议问题