{"id":139,"date":"2020-10-04T23:26:30","date_gmt":"2020-10-04T21:26:30","guid":{"rendered":"http:\/\/www.mbarsinai.com\/blog\/?p=139"},"modified":"2020-10-04T23:26:30","modified_gmt":"2020-10-04T21:26:30","slug":"maven-local-is-the-new-remote","status":"publish","type":"post","link":"https:\/\/www.mbarsinai.com\/blog\/2020\/10\/04\/maven-local-is-the-new-remote\/","title":{"rendered":"Maven: Local is the New Remote"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Often I stumble into a case where I need to use Maven, but also use specific, non-published .jar files. In Ant&#8217;s world, you&#8217;d just throw these in a local directory in the project&#8217;s dir. That would be simple. Handling the transitive dependencies of the rest of the jars would not be. Which is why Maven rocks and we should all be using it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But then there are the local-only jars.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So here is the solution I ended up using: have a local repository in the project&#8217;s directory, and deploy the jars there. This way, that repository can go into your version control system (i.e. git repo) and you can use Maven normally. Here&#8217;s how it&#8217;s done.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>a) Create local repository. <\/strong>This is easy, just make a directory, and call it &#8220;lib&#8221; or something.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>b) Register the repository in your pom.xml<\/strong>. Like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;repositories>\n  &lt;repository>\n    &lt;id>project.local&lt;\/id>\n    &lt;name>project&lt;\/name>\n    &lt;url>file:${project.basedir}\/lib&lt;\/url>\n  &lt;\/repository>\n&lt;\/repositories><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>c) Add a jar to that repo.<\/strong>  This is done from the commandline, using <a href=\"https:\/\/maven.apache.org\/plugins\/maven-deploy-plugin\/deploy-file-mojo.html\">mvn:deploy-file <\/a>command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mvn deploy:deploy-file \\\n-Dfile=\/path\/to\/jarfile.jar  \\\n-Durl=file:\/\/\/path\/to\/the\/project\/lib\/ \\\n-DgroupId=somegroupname \\\n-DartifactId=artifactname \\\n-Dversion=0.9 \\\n-Dpackaging=jar \\<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Clarifications:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>backslashes (&#8220;\\&#8221;) are for escaping new lines, so the command is easier to read. They can be omitted, along with the newlines (&#8220;\\n&#8221;s).<\/li><li>version 0.9 is as made up as the group name and the artifact id.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>d) Use your jar the Maven way <\/strong>by adding it as a dependency<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependencies>\n     &lt;dependency>\n         &lt;groupId>somegroupname&lt;\/groupId>\n         &lt;artifactId>artifactname&lt;\/artifactId>\n         &lt;version>0.9&lt;\/version>\n     &lt;\/dependency>\n    ... regular dependencies ...\n&lt;\/dependencies><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it! Pretty simple, and now that I&#8217;ve finally written it down, I won&#8217;t have to search for this solution over and overt again. Hopefully.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often I stumble into a case where I need to use Maven, but also use specific, non-published .jar files. In Ant&#8217;s world, you&#8217;d just throw these in a local directory in the project&#8217;s dir. That would be simple. Handling the transitive dependencies of the rest of the jars would not be. Which is why Maven [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[18,17],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-maven","tag-tip"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3NnQg-2f","_links":{"self":[{"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":2,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mbarsinai.com\/blog\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}