简体   繁体   中英

How to Run Eclipse+Maven+JUnit tests in Command Line

When I run mvn clean test , it gives me the following error:

'mvn' is not recognized as an internal or external command, operable program or batch file."

This is the link of my project.

I can run the tests by right-clicking on the Runner.java => Run as => JUnit Test . I can also run the tests from the JUnit 4 Test Explorer Tab.

I have read some articles where it's suggesting to set the PATH for Maven but all of them are about the case where you are installing Maven separately. I am not sure what PATH do I need to set when Maven is coming with Eclipse.

I did not install Maven separately, it came with my Eclipse version. My Eclipse Version :

Eclipse IDE for Java Developers
Version: 2019-03 (4.11.0)
Build id: 20190314-1200

This error means that Windows cannot find an executable program called "mvn". This means it is not on your path/current directory.

When you right click and run your junit tests, it invokes it using the JVM, using the java command. I suspect if you type "java -v" into CMD, it will not give you the same error.

Since Windows does not know where to look for maven, you must tell it implicitly, by setting your path to the directory containing the mvn executable. You can lookup "eclipse bundled maven default location" to find this, although it might be worth downloading it separately from the Apache website, and manually specifying the path.

Some IDEs (IntelliJ for example) have their own version of maven for internal purpose. But it doesn't mean that's able to be used by the command line. If you want to compile your project using mvn clean install/package/deploy/test/etc you must install maven in your machine and set de VARs in the OS.

I guess Eclipse has the same behavior that Intellij, so please also install maven in your machine

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM