title: configure swagger-ui with maven
body: <p>I am integrating my JAX-RS REST project with Swagger.
  I read many documentation and tutorials and my favourite figure is the following (thanks to <a href="https://blog.philipphauer.de/enriching-restful-services-swagger/" rel="nofollow noreferrer">Philipp Hauer's blog</a>):</p>
  <p><a href="https://i.stack.imgur.com/viQ9z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/viQ9z.png" alt="enter image description here" /></a></p>
  <p>That image helped me a lot to understand how Swagger works.</p>
  <p>After I have learned how Swagger works I modified my <code>pom.xml</code>.</p>
  <p>I added <code>swagger-jersey2-jaxrs</code> dependencies to my project which enable me to use the related <a href="https://github.com/swagger-api/swagger-core/wiki/annotations" rel="nofollow noreferrer">swagger annotations</a>:</p>
  <pre><code>&lt;!-- for Swagger-Core Annotations --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;io.swagger&lt;/groupId&gt;
      &lt;artifactId&gt;swagger-jersey2-jaxrs&lt;/artifactId&gt;
      &lt;version&gt;1.5.13&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p><strong>Important:</strong> I am not able to use the latest 1.15.18 swagger-jersey2-jaxrs dependency because the guava library belongs to this dependency made a serious classloader issue with the latest (v5.181) <a href="https://www.payara.fish/downloads" rel="nofollow noreferrer">Payara</a> appserver:</p>
  <pre><code>  Exception Occurred :Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;. Please see server.log for more details. ]]
  </code></pre>
  <p>Anyway, added the following plugin to my pom.xml as well which download the <code>swagger-ui</code> part and unpack it to the maven target folder:</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;com.googlecode.maven-download-plugin&lt;/groupId&gt;
      &lt;artifactId&gt;download-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.4.0&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;swagger-ui&lt;/id&gt;
              &lt;phase&gt;prepare-package&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;wget&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                  &lt;url&gt;https://github.com/swagger-api/swagger-ui/archive/v${version.swagger-ui}.tar.gz&lt;/url&gt;
                  &lt;unpack&gt;true&lt;/unpack&gt;
                  &lt;outputDirectory&gt;${project.build.directory}&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  <p>Here my issue was that I am behind proxy server so I had to add HTTPS proxy configuration to maven setting.xml.</p>
  <p>Finnaly I added <code>maven-war-plugin</code> to the pom.xml which copy the swagger-ui related static files to my final war file:</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
      &lt;version&gt;3.2.0&lt;/version&gt;
      &lt;configuration&gt;
          &lt;warName&gt;${project.build.finalName}&lt;/warName&gt;
          &lt;webappDirectory&gt;${basedir}/target/${project.build.finalName}&lt;/webappDirectory&gt;
          &lt;webResources&gt;
              &lt;webResource&gt;
                  &lt;directory&gt;${project.build.directory}/swagger-ui-${version.swagger-ui}/dist&lt;/directory&gt;
                  &lt;targetPath&gt;swagger&lt;/targetPath&gt;
              &lt;/webResource&gt;
          &lt;/webResources&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  <p>I initialize swagger documentation generator with the following code:</p>
  <pre><code>@ApplicationPath(&quot;api&quot;)
  public class Configurator extends Application {
      public Configurator() {
          BeanConfig beanConfig = new BeanConfig();
          beanConfig.setVersion(&quot;1.0.0&quot;);
          beanConfig.setSchemes(new String[]{&quot;http&quot;});
          beanConfig.setHost(&quot;localhost:8080&quot;);
          beanConfig.setBasePath(&quot;my-rest-1.0.0/api&quot;);
          beanConfig.setResourcePackage(EchoRest.class.getPackage().getName());
          beanConfig.setTitle(&quot;JAX-RS + Swagger and Swagger UI Example&quot;);
          beanConfig.setDescription(&quot;Sample RESTful API built using JAX-RS, Swagger and Swagger UI&quot;);
          beanConfig.setScan(true);
      }
  }
  </code></pre>
  <p>It works fine, the http://localhost:8080/my-rest-1.2.0/api/swagger.json returns with a proper swagger documentation.</p>
  <p><strong>BUT</strong></p>
  <ol>
  <li>I need to overwrite the hardcoded url value in the JavaScript part of the <code>swagger/index.html</code> file from the default <a href="http://petstore.swagger.io/v2/swagger.json" rel="nofollow noreferrer">http://petstore.swagger.io/v2/swagger.json</a> to my URL. I download and copy swagger-ui via maven plugins automatically but I do not know how to change the value of the URL variable automatically during compiling with maven.</li>
  <li>The name of my WAR file depends on the version information used in maven pom.xml. That means that the hard-coded version, host and base-path used in <code>Configurator</code> class wont be correct after a while. Can I generate this values automatically based on the application root url and the value from @ApplicationPath(&quot;api&quot;) annotation?</li>
  </ol>