<div dir="ltr" style="text-align: justify;">Here we are creating simple Maven Example Hello World using command prompt by executing the archetype:generate command of mvn tool.First of all going to any directory of computer machine and open command prompt. Here I am using git bash as command prompt. For creating a simple hello java project using maven, we have to open command prompt and run the archetype:generate command of mvn tool.</p>
<p>The command as following we have used to create project-</p>
<h2><b>Command-</b></h2>
<pre class="highlight">mvn archetype:generate -DgroupId=groupid -DartifactId=artifactid 
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=booleanValue 
</pre>
<h2><b>Creating Java Hello World Maven Project</b></h2>
<p>Above is the syntax for creating java project so let see below for actually create command.</p>
<pre class="highlight">mvn archetype:generate -DgroupId=com.dineshonjava -DartifactId=JavaHelloWorld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 
</pre>
<p>After running this command following is output:</p>
<p>Now it will generate following code in the command prompt:</p>
<pre class="highlight">$ mvn archetype:generate -DgroupId=com.dineshonjava -DartifactId=JavaHelloWorld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 
[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Maven Stub Project (No POM) 1 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] >;>;>; maven-archetype-plugin:2.4:generate (default-cli) >; generate-sources @ standalone-pom >;>;>; 
[INFO] 
[INFO] <;<;<; maven-archetype-plugin:2.4:generate (default-cli) <; generate-sources @ standalone-pom <;<;<; 
[INFO] 
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom --- 
[INFO] Generating project in Batch mode 
[INFO] ---------------------------------------------------------------------------- 
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0 
[INFO] ---------------------------------------------------------------------------- 
[INFO] Parameter: groupId, Value: com.dineshonjava 
[INFO] Parameter: packageName, Value: com.dineshonjava 
[INFO] Parameter: package, Value: com.dineshonjava 
[INFO] Parameter: artifactId, Value: JavaHelloWorld 
[INFO] Parameter: basedir, Value: D:personal datadojmaven-tutorails 
[INFO] Parameter: version, Value: 1.0-SNAPSHOT 
[INFO] project created from Old (1.x) Archetype in dir: D:personal datadojmaven-tutorailsJavaHelloWorld 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 01:03 min 
[INFO] Finished at: 2016-10-24T23:58:00+05:30 
[INFO] Final Memory: 9M/44M 
[INFO] ------------------------------------------------------------------------ 
 
</pre>
<div id="ads-id" align="center"></div>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2016/10/Maven-Example-Hello-World.jpg" width="740" height="253" border="0" /></div>
<h2><b>Created Project Structure-</b></h2>
<p>Now go to directory where we have created java project. We got following directory structure.</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2016/10/Maven-dirctory-structure.jpg" border="0" /></div>
<h3><b>Created files:</b></h3>
<p>Following files are auto generated into java project.<br />
<b></b></p>
<h3><b>Maven pom.xml file</b></h3>
<pre class="highlight"><;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">; 
 <;modelVersion>;4.0.0<;/modelVersion>; 
 <;groupId>;com.dineshonjava<;/groupId>; 
 <;artifactId>;JavaHelloWorld<;/artifactId>; 
 <;packaging>;jar<;/packaging>; 
 <;version>;1.0-SNAPSHOT<;/version>; 
 <;name>;JavaHelloWorld<;/name>; 
 <;url>;http://maven.apache.org<;/url>; 
 <;dependencies>; 
 <;dependency>; 
 <;groupId>;junit<;/groupId>; 
 <;artifactId>;junit<;/artifactId>; 
 <;version>;3.8.1<;/version>; 
 <;scope>;test<;/scope>; 
 <;/dependency>; 
 <;/dependencies>; 
<;/project>; 
 
</pre>
<p><b>App.java</b></p>
<pre class="highlight">package com.dineshonjava; 
 
/** 
 * Hello world! 
 * 
 */ 
public class App 
{ 
 public static void main( String[] args ) 
 { 
 System.out.println( "Hello World!" ); 
 } 
} 
 
</pre>
<p><b>AppTest.java</b></p>
<pre class="highlight">package com.dineshonjava; 
 
import junit.framework.Test; 
import junit.framework.TestCase; 
import junit.framework.TestSuite; 
 
/** 
 * Unit test for simple App. 
 */ 
public class AppTest 
 extends TestCase 
{ 
 /** 
 * Create the test case 
 * 
 * @param testName name of the test case 
 */ 
 public AppTest( String testName ) 
 { 
 super( testName ); 
 } 
 
 /** 
 * @return the suite of tests being tested 
 */ 
 public static Test suite() 
 { 
 return new TestSuite( AppTest.class ); 
 } 
 
 /** 
 * Rigourous Test :-) 
 */ 
 public void testApp() 
 { 
 assertTrue( true ); 
 } 
} 
 
</pre>
<h3><b>Run the created java project</b></h3>
<p>For running created java project we have to compile first then we can run it.</p>
<p>For compile use this command &#8220;<b>mvn clean compile</b>&#8221;</p>
<pre class="highlight">$ mvn clean compile 
[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building JavaHelloWorld 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ JavaHelloWorld --- 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JavaHelloWorld --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory D:personal datadojmaven-tutorailsJavaHelloWorldsrcmainresources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ JavaHelloWorld --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
[INFO] Compiling 1 source file to D:personal datadojmaven-tutorailsJavaHelloWorldtargetclasses 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.829 s 
[INFO] Finished at: 2016-10-25T00:19:50+05:30 
[INFO] Final Memory: 9M/22M 
[INFO] ------------------------------------------------------------------------ 
 
</pre>
<p>For run this project go to the project <b>directorytargetclasses</b>,</p>
<p>And run following command for executing java class.</p>
<p><i>java com.dineshonjava.App</i></p>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/maven-settings-file/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/maven-project-dependencies/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '103'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…