How to create the java stand alone project with command prompt using maven

To create a simple java project using maven, you need to open the command prompt and run the archetype: generate command of the mvn tool.

The syntax is given below:

mvn archetype:generate -DgroupId=groupid -DartifactId=artifactid -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=booleanValue

Here group id means =package name
Here artifact id menas=project name
DarchetypeArtifactId means =It is an archetype which generates a sample Maven project
DarchetypeVersion means=version of your project
Interactive mode means = If the flag value is false(the project is created in batch mode, batch-mode will automatically use default values instead of asking you via prompt for those values). when -DinteractiveMode=true, then project is created in interactive mode.

Steps to create the sample stand-alone project with maven.

Step1: After successful installation maven opens the command prompt.
Step2: Type the below command
mvn archetype:generate -DgroupId=com.quickdevops -DartifactId=sample -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

It will generate the project directory structure with 3 files  those are:
  • Pom.xml
  • App.java
  • AppTest.java
Here is my pom.xml file
<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.quickdevops</groupId>  
  <artifactId>sample</artifactId>  
  <packaging>jar</packaging>  
  <version>1.0-SNAPSHOT</version>  
  <name>CubeGenerator</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>
Here is my App.java 
 package com.quickdevops;  
    /** 
     * Hello world! 
     * 
     */  
    public class App   
    {  
        public static void main( String[] args )  
        {  
            System.out.println( "Hello World!" );  
        }  
    }  
Here is my AppTest.java
package com.quickdevops;  
      
    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 );  
        }  
    }  

To run the application following the commands

  • For Cleaning the project: mvn clean
  • For compiling the project: mvn compile
  • For packaging the project: mvn package, mvn install (it will generate the jar file).
  • To run the project (Go to target and folder open the command prompt type the following command: java -jar filename.) 

SUBSCRIBE TO OUR NEWSLETTER

I’m the Founder of quickdevops.com. I am a Professional Blogger, Application developer, YouTuber. I’ve been blogging since 2015.I spend a lot of time learning new techniques and actively help other people learn web development through a variety of help groups and writing web development tutorials for my website and blog about advancements in web design and development.Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie or planning a trip to someplace I've never been before.

2 Responses to "How to create the java stand alone project with command prompt using maven"

  1. 797222901A8C
    Sosyal medya yönetimi konusunda uygun fiyatlı çözümler arıyorsanız ucuz smm panel seçeneklerini inceleyebilirsiniz. Bu panel sayesinde hem zaman kazanabilir hem de bütçenizi koruyarak etkili sonuçlar elde edebilirsiniz. Uygun fiyatlı olmasıyla bilinen ucuz smm panel birçok kullanıcı tarafından tercih edilmektedir. Sosyal medya büyümeniz için ideal bir araçtır.

    ReplyDelete