{"id":195,"date":"2019-03-06T04:02:56","date_gmt":"2019-03-06T04:02:56","guid":{"rendered":"http:\/\/localhost:8888\/wordpress\/?p=195"},"modified":"2024-07-11T02:24:30","modified_gmt":"2024-07-11T02:24:30","slug":"how-to-create-maven-project","status":"publish","type":"post","link":"https:\/\/mendzeleu.net\/wp_mendzeleu\/?p=195","title":{"rendered":"How to create Maven project"},"content":{"rendered":"\n<p class=\"has-black-color has-text-color has-link-color wp-elements-7cd3ea294b437cb6503b952c8c404812\">First of all you need to check if you have maven installed<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-ae5d610952860052b3b2237bf74223db\"><code>mvn -v<\/code><\/pre>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-0435adc7ec9cffa60dae3d8bf1ab987b\">This is something what you should see<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-53c43261f697c9dd514b611e97440fbc\"><code>Apache Maven 3.5.2\nMaven home: \/usr\/share\/maven\nJava version: 1.8.0_191, vendor: Oracle Corporation\nJava home: \/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre\nDefault locale: en_CA, platform encoding: UTF-8\nOS name: \"linux\", version: \"4.18.0-15-generic\", arch: \"amd64\", family: \"unix\"<\/code><\/pre>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-60039c1880a066515d26a6d170e8cdf5\">You should see version of maven installed, version of your java, version of OS that you using. In my case it was maven 3.5.2 open jdk 8 and linux OS.<\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-7d9570f1f6ce21a8560b91a2a285cf29\">Maven is plugin based tool. To create new project you will need to use <strong>archetype<\/strong> plugin with goal <strong>generate<\/strong>. More specifically it will look like:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-2c9a9b1e2327fb9074f03fbcb0bba2fb\"><code>mvn archetype:generate \n    -DgroupId={project-goup} \n    -DartifactId={project-name} \n    -Dversion={initial version of project} \n    -DarchetypeGroupId={maven-template-group} \n    -DarchetypeArtifactId={maven-template-name} <\/code><\/pre>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-09c58ff00df6ed31d7ccca79c794fe3c\">Maven operates with 2 categories when it comes to projects. First is group which is represented by groupId. It has package style naming. Example: net.mendzeleu.  Second is artifact which is represented by artifactId. This is basically name of the project. The idea is that combination of groupId and artifactId should  uniquely identify all projects on the planet. \ud83d\ude42 That&#8217;s why it is recommended to have company name or individual name in group id.<\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-cf65d5d3f603566fe23c9af96c15e96f\">Same concept is applicable to archetype which is basically templates for the projects. Here are few useful archetypes:<\/p>\n\n\n\n<p class=\"has-text-align-left has-black-color has-text-color has-link-color wp-elements-f351d2eebaa5b0958cb7c3a16c3cb8c3\"><strong>org.apache.maven.archetypes:maven-archetype-quickstart<\/strong> &#8211; simple java project<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-a5f2265ae426468d2df57f5b7c297673\"><code>mvn archetype:generate -DgroupId=net.mendzeleu -DartifactId=lib -Dversion=1.0-SNAPSHOT  -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart <\/code><\/pre>\n\n\n\n<p>It will create structure as displayed below<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"580\" src=\"http:\/\/127.0.0.1:8888\/wp-content\/uploads\/2019\/03\/image-1.png\" alt=\"\" class=\"wp-image-202\" srcset=\"https:\/\/mendzeleu.net\/wp_mendzeleu\/wp-content\/uploads\/2019\/03\/image-1.png 595w, https:\/\/mendzeleu.net\/wp_mendzeleu\/wp-content\/uploads\/2019\/03\/image-1-300x292.png 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-2b48039896491415d3824e25cdd754fa\"><strong>org.apache.maven.archetypes:maven-archetype-webapp<\/strong> &#8211; simple web project<br><\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-405f1cc9eed443a280a05733e5cae9d4\"><code>mvn archetype:generate -DgroupId=net.mendzeleu -DartifactId=weblib  -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp <\/code><\/pre>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-362b563920e4612dbec1ca324d997024\">It will create structure as displayed below<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"363\" src=\"http:\/\/127.0.0.1:8888\/wp-content\/uploads\/2019\/03\/image-3.png\" alt=\"\" class=\"wp-image-203\" srcset=\"https:\/\/mendzeleu.net\/wp_mendzeleu\/wp-content\/uploads\/2019\/03\/image-3.png 581w, https:\/\/mendzeleu.net\/wp_mendzeleu\/wp-content\/uploads\/2019\/03\/image-3-300x187.png 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-7cb62a493c87d83a07a3786672e33602\">Please make sure you have internet connection before you first time compile your project. Maven will try to download all dependencies and required plugins automatically.<\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-83f664b0847e8fceb75e64e8952a5401\">To compile your project, execute following command in root folder of your project:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-9da9dc638187632cab26f6d5e67775a0\"><code>mvn clean install<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First of all you need to check if you have maven installed This is something what you should see You should see version of maven installed, version of your java, version of OS that you using. In my case it was maven 3.5.2 open jdk 8 and linux OS. Maven is plugin based tool. To [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8,9],"class_list":{"0":"post-195","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-java","7":"tag-java","8":"tag-maven","9":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/posts\/195"}],"collection":[{"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":13,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mendzeleu.net\/wp_mendzeleu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}