Learn to create a Java application project with maven, using interactive and non-interactive modes from the command prompt.
1. Using Maven Non-interactive Mode
In non-interactive mode, Maven creates a blank Java project with all default options applicable for the selected Maven template. To create this, type the below command.
//Remove the new line characters. This command should be in a single line. $ mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=DemoJavaProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will create a blank java project named DemoJavaProject in the workspace. You can choose and use your own application name. We can see what happens when you run the above command in the below image.
We can see in step 2, that the Java project has standard folders created and a default
pom.xml has also been created in the project root.
2. Using Maven Interactive Mode
In interactive mode, We just need to start with “mvn archetype:generate” and the rest of the options will be specified using a wizard which will come one by one.
$ mvn archetype:generate
The wizard stops at where it will ask for archetypeArtifactId. Wizard will present us a list of numbers to choose from or filter among them (because the options list is very long).
We need to choose option 18 for our simple java project.
Finally, choose the archetype version as 5 (or any other of your choice), and
groupId as “com.howtodoinjava“.
Finally, choose the artifactId that is the desired project name. Now, there will be some other options and confirmations. Answer them, and our project is ready.
We can see that our project is created with the default source folder and
Happy Learning !!