<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Loading non-repo jars with Maven</title><link>https://community.element14.com/technologies/code_exchange/w/documents/1615/loading-non-repo-jars-with-maven</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>Loading non-repo jars with Maven</title><link>https://community.element14.com/technologies/code_exchange/w/documents/1615/loading-non-repo-jars-with-maven</link><pubDate>Wed, 06 Oct 2021 20:51:49 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:10eaa62a-441c-47c1-9574-d773c85ab998</guid><dc:creator>PEarle</dc:creator><comments>https://community.element14.com/technologies/code_exchange/w/documents/1615/loading-non-repo-jars-with-maven#comments</comments><description>Current Revision posted to Documents by PEarle on 10/6/2021 8:51:49 PM&lt;br /&gt;
&lt;p style="margin:0;"&gt;A circumstance may arise whereby a jar file is required for a project which is not in maven. This has happened recently in a project I worked on which requires a Websphere MQ jar, which is not available via maven.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;The jar can be included into the project as follows - the main steps are&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy the jar to a file location within the project&lt;/li&gt;&lt;li&gt;Use the maven-install-plugin to load the jar from the file system rather than from the maven repo&lt;/li&gt;&lt;li&gt;Dependencies are defined in pom.xml as normal (see version number below)&lt;/li&gt;&lt;/ul&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;Deploy jar file to project location&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;The jar file needs to be deployed to a repo location - maven has a command to do this as follows ;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;mvn install:install-file -Dfile=&amp;lt;jar_file_to_deploy&amp;gt; -DgroupId=&amp;lt;groupid&amp;gt; -DartifactId=&amp;lt;?artifactid?&amp;gt; -Dversion=&amp;lt;version&amp;gt; -Dpackaging=jar -DlocalRepositoryPath=&amp;lt;deployment_location&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;E.g. for the &lt;strong&gt;mq.jar&lt;/strong&gt;, which is group id &lt;strong&gt;com.ibm&lt;/strong&gt;, artifact id &lt;strong&gt;mq&lt;/strong&gt; use the following command&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mvn install:install-file -Dfile=C:\peter\mqjms-9.0.jar -DgroupId=com.ibm -DartifactId=mq -Dversion=9.0 -Dpackaging=jar -DlocalRepositoryPath=E:\Repos\Git\mqbridge\repo&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Note the version - this is set artificially high to ensure hat it doesn not conflict with any pre-existing maven version&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;maven-install-plugin&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;The &lt;strong&gt;pom.xml&lt;/strong&gt; file needs to know that it should load the jar file from the file store, rather than from the maven repository. This can be achieved as shown below.&lt;/p&gt;&lt;p style="margin:0;"&gt;Note that multiple executions are used for multiple files. It should be noted that the files are loaded during the install-file phase of the build - to ensure that this goal is implemented, the project should be built with the &amp;#39;clean&amp;#39; parameter (e.g. &lt;em&gt;mvn clean install&lt;/em&gt;)&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="xml"&gt;&amp;lt;plugin&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-install-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;executions&amp;gt;
        &amp;lt;execution&amp;gt;
            &amp;lt;id&amp;gt;install-mq&amp;lt;/id&amp;gt;
            &amp;lt;phase&amp;gt;process-resources&amp;lt;/phase&amp;gt;
            &amp;lt;goals&amp;gt;
                &amp;lt;goal&amp;gt;install-file&amp;lt;/goal&amp;gt;
            &amp;lt;/goals&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;groupId&amp;gt;com.ibm&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;mq&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;9.0&amp;lt;/version&amp;gt;
                &amp;lt;packaging&amp;gt;jar&amp;lt;/packaging&amp;gt;
                &amp;lt;file&amp;gt;${project.basedir}/repo/com/ibm/mq/9.0/mq-9.0.jar&amp;lt;/file&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/execution&amp;gt;
        &amp;lt;execution&amp;gt;
            &amp;lt;id&amp;gt;install-mqjms&amp;lt;/id&amp;gt;
            &amp;lt;phase&amp;gt;process-resources&amp;lt;/phase&amp;gt;
            &amp;lt;goals&amp;gt;
                &amp;lt;goal&amp;gt;install-file&amp;lt;/goal&amp;gt;
            &amp;lt;/goals&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;groupId&amp;gt;com.ibm&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;mqjms&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;9.0&amp;lt;/version&amp;gt;
                &amp;lt;packaging&amp;gt;jar&amp;lt;/packaging&amp;gt;
                &amp;lt;file&amp;gt;${project.basedir}/repo/com/ibm/mqjms/9.0/mqjms-9.0.jar&amp;lt;/file&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/execution&amp;gt;
    &amp;lt;/executions&amp;gt;
&amp;lt;/plugin&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;Define dependencies&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Dependencies are defined as normal - the version number should match the version used when the jar file was deployed to the file system (see above).&lt;/p&gt;&lt;p style="margin:0;"&gt;E.g.&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="xml"&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.ibm&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;mq&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;9.0&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.ibm&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;mqjms&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;9.0&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>