Let’s add the Maven assembly plugin in the pom. This increases its overall size, but ensures that we can run it as a standalone executable using the java -jar command. This plugin includes all of our applications dependencies into the JAR file.
![how to do a clean maven install comman line how to do a clean maven install comman line](https://www.andreaseisele.com/posts/mvn-clean-install/multi_module.png)
To enable this, we can use the maven-assembly-plugin. This happens because by default, maven doesn’t bundle the dependency class files along with the application code. It looks like the Java class loader couldn’t find the classes for the Cowsay library, even though we added it as a dependency in the pom.xml file. $ java -jar target/Įxception in thread "main" : com/github/ricksbrown/cowsay/CowsayĬaused by: : .CowsayĪt java.base/.loadClass(BuiltinClassLoader.java:641)Īt java.base/$AppClassLoader.loadClass(ClassLoaders.java:188)Īt java.base/(ClassLoader.java:520) Maven allows us to install these dependencies by specifying them in our pom.xml file.įor this example, let’s install the Cowsay library, which will display our output as a quote from a friendly cartoon figure of a cow.įirst, we have to add Cowsay as a dependency in our pom.xml file:
#HOW TO DO A CLEAN MAVEN INSTALL COMMAN LINE HOW TO#
Let’s look at how to add dependencies and package them in our JAR file.įor most applications need external libraries (like Spring Boot or Apache Commons) to implement common functionality. You need to provide the mvn command with the life cycle phase or goal to execute. The command should be executed in the directory which contains the relevant pom file. Install will then compile, test & package your Java project and even install/copy your built. To build a Maven project via the command line, run the mvn command from the command line.
![how to do a clean maven install comman line how to do a clean maven install comman line](https://www.journaldev.com/wp-content/uploads/2019/12/Maven-Commands-Cheat-Sheet.png)
Your build will start from a clean slate. To run tests, we can run the mvn test command - this will run all tests, tell us how many passed and failed, and give us more information about the failed tests. (see How do you install Maven) You are using the clean command, which will delete all previously compiled Java. Test public class AppTest īy default, the maven project folder comes bundled with the JUnit library for running unit tests sohamkamani // the JUnit library is used for testing import static org.