{"id":6,"date":"2012-08-03T23:47:37","date_gmt":"2012-08-03T23:47:37","guid":{"rendered":"http:\/\/softwareeveryday.wordpress.com\/?p=4"},"modified":"2012-08-03T23:47:37","modified_gmt":"2012-08-03T23:47:37","slug":"parametrize-anything-using-maven-resource-filtering","status":"publish","type":"post","link":"https:\/\/www.softwareeverydayblog.com\/?p=6","title":{"rendered":"Parametrize anything using maven Resource filtering."},"content":{"rendered":"<p>Was trying to\u00a0Parametrize\u00a0persistence.xml in src\/main\/resources\/META-INF . \u00a0Came accross concept of \u00a0Resource Filtering by maven Resources plugin.<\/p>\n<p>1. <strong>Replace values with variables in whichever file you want.<\/strong><\/p>\n<p>&lt;property name=&#8221;hibernate.connection.driver_class&#8221; value=&#8221;${my.driverClassName}&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;hibernate.connection.url&#8221; value=&#8221;${my.url}&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;hibernate.connection.username&#8221; value=&#8221;${my.user}&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;hibernate.connection.password&#8221; value=&#8221;${my.password}&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;hibernate.dialect&#8221; value=&#8221;${my.dialect}&#8221;\/&gt;<\/p>\n<p>2. <strong>Create profile in pom xml<\/strong><\/p>\n<p>&lt;profiles&gt;<br \/>\n&lt;profile&gt;<br \/>\n&lt;id&gt;myprofile&lt;\/id&gt;<br \/>\n&lt;properties&gt;<br \/>\n&lt;my.driverClassName&gt;oracle.jdbc.driver.OracleDriver&lt;\/my.driverClassName&gt;<br \/>\n&lt;my.url&gt;jdbc:oracle:thin:@localhost:1521:orcl&lt;\/my.url&gt;<br \/>\n&lt;my.user&gt;myuser&lt;\/my.user&gt;<br \/>\n&lt;my.password&gt;mypass&lt;\/my.password&gt;<br \/>\n&lt;my.dialect&gt;org.hibernate.dialect.Oracle9iDialect&lt;\/my.dialect&gt;<br \/>\n&lt;\/properties&gt;<br \/>\n&lt;\/profile&gt;<br \/>\n&lt;\/profiles&gt;<\/p>\n<p>3. <strong>Activate resource filtering<\/strong><\/p>\n<p>&lt;build&gt;<br \/>\n&lt;resources&gt;<br \/>\n&lt;resource&gt;<br \/>\n&lt;directory&gt;src\/main\/resources&lt;\/directory&gt;<br \/>\n&lt;filtering&gt;true&lt;\/filtering&gt;<br \/>\n&lt;\/resource&gt;<br \/>\n&lt;\/resources&gt;<br \/>\n&lt;\/build&gt;<\/p>\n<p>You need to do this, by default filtering is disabled. Even if your files are within subfolders of\u00a0src\/main\/resources it will filter them. For example in this case\u00a0\u00a0persistence.xml \u00a0is in\u00a0src\/main\/resources\/META-INF and it works ok.<\/p>\n<p>4. <strong>Run maven like this:-<\/strong><\/p>\n<p>mvn clean install -Pmyprofile<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.sonatype.com\/books\/mvnref-book\/reference\/resource-filtering-sect-description.html\">http:\/\/www.sonatype.com\/books\/mvnref-book\/reference\/resource-filtering-sect-description.html<\/a><\/p>\n<p><a href=\"http:\/\/maven.apache.org\/plugins\/maven-resources-plugin\/examples\/filter.html\">http:\/\/maven.apache.org\/plugins\/maven-resources-plugin\/examples\/filter.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Was trying to\u00a0Parametrize\u00a0persistence.xml in src\/main\/resources\/META-INF . \u00a0Came accross concept of \u00a0Resource Filtering by maven Resources plugin. 1. Replace values with variables in whichever file you want. &lt;property name=&#8221;hibernate.connection.driver_class&#8221; value=&#8221;${my.driverClassName}&#8221; \/&gt; &lt;property name=&#8221;hibernate.connection.url&#8221; value=&#8221;${my.url}&#8221; \/&gt; &lt;property name=&#8221;hibernate.connection.username&#8221; value=&#8221;${my.user}&#8221; \/&gt; &lt;property name=&#8221;hibernate.connection.password&#8221; value=&#8221;${my.password}&#8221; \/&gt; &lt;property name=&#8221;hibernate.dialect&#8221; value=&#8221;${my.dialect}&#8221;\/&gt; 2. Create profile in pom xml &lt;profiles&gt; &lt;profile&gt; &lt;id&gt;myprofile&lt;\/id&gt; &lt;properties&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":0,"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwareeverydayblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}