{"id":1045,"date":"2010-07-16T20:58:11-04:00","date_gmt":"2010-07-17T00:58:11+00:00","guid":{"rendered":"http:\/\/peterjanes.ca\/blog\/?p=1045"},"modified":"2010-07-27T08:16:19-04:00","modified_gmt":"2010-07-27T12:16:19+00:00","slug":"a-pattern-for-webstart-in-maven","status":"publish","type":"post","link":"https:\/\/peterjanes.ca\/blog\/2010\/07\/16\/a-pattern-for-webstart-in-maven\/","title":{"rendered":"A pattern for WebStart in&nbsp;Maven"},"content":{"rendered":"<div class='e-content'><p>Java <a href=\"http:\/\/java.sun.com\/javase\/technologies\/desktop\/javawebstart\/index.jsp\">WebStart<\/a> and <a href=\"http:\/\/download.oracle.com\/docs\/cd\/E17476_01\/javase\/1.5.0\/docs\/guide\/javaws\/developersguide\/syntax.html\">JNLP<\/a> can be finicky beasts, especially when paired with Maven-generated websites and artifact repositories.  Over the last few months I&#8217;ve developed POM and JNLP template patterns that I think are useful when used with the <a href=\"http:\/\/mojo.codehaus.org\/webstart\/webstart-maven-plugin\/jnlp-mojos-overview.html\">webstart-maven-plugin:jnlp<\/a> goal; the main advantage is that applications can be WebStarted directly from the repository, which means that the version available is always the latest <code>-SNAPSHOT<\/code> or release.<\/p>\r\n\r\n<p>In the POM I define two variables, <code>site.baseUrl<\/code> and <code>artifactUrl<\/code>.  <code>site.baseUrl<\/code> defines the server and root path where all Maven-generated websites are published; it has a prefix because usually I&#8217;d only set it once in the corporate POM. <code>artifactUrl<\/code> is the full URL of the project-specific website.<\/p>\r\n\r\n<p>By default both <code>site.baseUrl<\/code> and <code>artifactUrl<\/code> point to the location where <code>-SNAPSHOT<\/code> sites are published, usually by a <abbr title=\"continuous integration\">CI<\/abbr> system.  They&#8217;re overridden in two profiles: <code>release<\/code> switches <code>site.baseUrl<\/code> to the release website (which is applied to <code>artifactUrl<\/code>, so there&#8217;s no need to set it again), and <code>devel<\/code> sets <code>artifactUrl<\/code> to the local target directory (and omits <code>site.baseUrl<\/code>, which ends up unused).<\/p>\r\n\r\n<pre><code>&lt;project&gt;<\/code>\r\n...\r\n<code>  &lt;properties&gt;\r\n    &lt;site.baseUrl&gt;http:\/\/repository\/snapshot-site\/&lt;\/site.baseUrl&gt;\r\n    &lt;artifactUrl&gt;${site.baseUrl}\/${project.artifactId}&lt;\/artifactUrl&gt;\r\n  &lt;\/properties&gt;<\/code>\r\n...\r\n<code>  &lt;profiles&gt;\r\n    &lt;profile&gt;\r\n      &lt;id&gt;release&lt;\/id&gt;\r\n      &lt;properties&gt;\r\n        &lt;site.baseUrl&gt;http:\/\/repository\/release-site\/&lt;\/site.baseUrl&gt;\r\n      &lt;\/properties&gt;\r\n      &lt;distributionManagement&gt;\r\n        &lt;site&gt;\r\n          &lt;id&gt;release-site&lt;\/id&gt;\r\n          &lt;url&gt;dav:${artifactUrl}&lt;\/url&gt;\r\n        &lt;\/site&gt;\r\n      &lt;\/distributionManagement&gt;\r\n    &lt;\/profile&gt;\r\n    &lt;profile&gt;\r\n      &lt;id&gt;devel&lt;\/id&gt;\r\n      &lt;properties&gt;\r\n        &lt;artifactUrl&gt;file:\/\/${project.build.directory}&lt;\/artifactUrl&gt;\r\n      &lt;\/properties&gt;\r\n    &lt;\/profile&gt;\r\n  &lt;\/profiles&gt;<\/code>\r\n...\r\n<code>&lt;\/project&gt;<\/code><\/pre>\r\n\r\n<p>In the JNLP template, the <code>codebase<\/code> is set to <code>artifactUrl<\/code>, which means that the resulting JNLP will retrieve any artifact dependencies from the snapshot, release or local output directories.<\/p>\r\n\r\n<pre><code>&lt;jnlp\r\n  spec=\"$jnlpspec\"\r\n  codebase=\"${artifactUrl}\/jnlp\/\"\r\n  version=\"$project.Version\"\r\n&gt;<\/code>\r\n...\r\n<code>&lt;\/jnlp&gt;<\/code><\/pre>\r\n\r\n<p>Note that the artifact dependencies still need to be copied into the <code>jnlp<\/code> directory, which <code>webstart-maven-plugin:jnlp<\/code> does by default.  It would be nice to be able to get them from their canonical locations on the repository, but that&#8217;s not easily accomplished.<\/p><\/div><div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"Java WebStart and JNLP can be finicky beasts, especially when paired with Maven-generated websites and artifact repositories. Over the last few months I&#8217;ve developed POM and JNLP template patterns that I think are useful when used with the webstart-maven-plugin:jnlp goal; the main advantage is that applications can be WebStarted directly from the repository, which means&hellip;","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"venue_id":0},"categories":[1],"tags":[],"kind":false,"_links":{"self":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts\/1045"}],"collection":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/comments?post=1045"}],"version-history":[{"count":7,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts\/1045\/revisions"}],"predecessor-version":[{"id":1052,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts\/1045\/revisions\/1052"}],"wp:attachment":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/media?parent=1045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/categories?post=1045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/tags?post=1045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}