{"id":6131,"date":"2022-10-10T20:18:33","date_gmt":"2022-10-10T20:18:33","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6131"},"modified":"2022-10-10T20:18:33","modified_gmt":"2022-10-10T20:18:33","slug":"maven-file-structure-basics","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/maven-file-structure-basics\/","title":{"rendered":"Maven file structure basics"},"content":{"rendered":"<p><em>This is an old blog post that sat in draft for years, int looks complete, so I thought I&#8217;d publish it. Hopefully it&#8217;s still upto date.<\/em><\/p>\n<p>As I&#8217;m working in Java again and using Maven a lot to get my projects up and running. Whilst I&#8217;ve covered some of this stuff in other posts, they&#8217;ve tended to be part of working with some specific code. So this post is mean&#8217;t to be more about using Maven itself.<\/p>\n<p><strong>Maven convention file structure<\/strong><\/p>\n<p>By default the following file structure is expected<\/p>\n<p>\/src\/main\/java<br \/>\n\/src\/main\/resources<br \/>\n\/src\/test\/java<\/p>\n<p>Optionally we might have the test\/resources<\/p>\n<p>\/src\/test\/resources<\/p>\n<p><strong>POM starting point<\/strong><\/p>\n<p>Maven (be default) expects a file name pom.xml to exist which contains version information and may include plugins, code generation, dependencies etc.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot;\r\n         xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\r\n         xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;\r\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\r\n    &lt;groupId&gt;com.putridparrot.common&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;JsonPatch&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\r\n&lt;\/project&gt;\r\n<\/pre>\n<p>Naming conventions (see references) <\/p>\n<p><strong>groupId<\/strong> &#8211; &#8220;identifies the project uniquely across all projects&#8221; hence might best be represented by the package name.<br \/>\n<strong>artifactId<\/strong> &#8211; is the name of the JAR<br \/>\n<strong>version<\/strong> &#8211; standard numbers with dots, i.e. 1.0, 1.0.1 etc.  This is a string so in situations where we want a version to include the word SNAPSHOT (for example) <\/p>\n<p><strong>Maven commands<\/strong><\/p>\n<p>Before we get into more POM capabilities, let&#8217;s look at the basic set of Maven command&#8217;s we&#8217;ll use most.<\/p>\n<p><strong>Compiling to specific Java versions<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;properties&gt;\r\n   &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;\r\n   &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;\r\n&lt;\/properties&gt;\r\n<\/pre>\n<p>OR<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;build&gt;\r\n   &lt;plugins&gt;\r\n      &lt;plugin&gt;\r\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\r\n        &lt;version&gt;3.7.0&lt;\/version&gt;\r\n        &lt;configuration&gt;\r\n          &lt;source&gt;1.8&lt;\/source&gt;\r\n          &lt;target&gt;1.8&lt;\/target&gt;\r\n        &lt;\/configuration&gt;\r\n      &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n&lt;\/build&gt;\r\n<\/pre>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/maven.apache.org\/guides\/mini\/guide-naming-conventions.html\" rel=\"noopener\" target=\"_blank\">Guide to naming conventions on groupId, artifactId and version<\/a><br \/>\n<a href=\"https:\/\/maven.apache.org\/plugins\/maven-compiler-plugin\/examples\/set-compiler-source-and-target.html\" rel=\"noopener\" target=\"_blank\">Setting the -source and -target of the Java Compiler<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an old blog post that sat in draft for years, int looks complete, so I thought I&#8217;d publish it. Hopefully it&#8217;s still upto date. As I&#8217;m working in Java again and using Maven a lot to get my projects up and running. Whilst I&#8217;ve covered some of this stuff in other posts, they&#8217;ve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[160],"tags":[],"class_list":["post-6131","post","type-post","status-publish","format-standard","hentry","category-maven"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6131"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6131\/revisions"}],"predecessor-version":[{"id":9543,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6131\/revisions\/9543"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}