title: how to use URI templates to change path parameters in a URL in java
body: <p>I followed the tutorial available in <a href="https://dzone.com/articles/using-uritemplate-change-path" rel="noreferrer">here</a> for replacing path parameters with given values and ran the sample code which is given below</p>
  
  <pre><code>import org.glassfish.jersey.uri.UriTemplate;
  
  import javax.ws.rs.core.UriBuilder;
  import java.net.URI;
  import java.util.HashMap;
  import java.util.Map;
  
  public class Demo {
      public static void main(String[] args) {
          String template = "http://example.com/name/{name}/age/{age}";
          UriTemplate uriTemplate = new UriTemplate(template);
          String uri = "http://example.com/name/Bob/age/47";
          Map&lt;String, String&gt; parameters = new HashMap&lt;&gt;();
  
          // Not this method returns false if the URI doesn't match, ignored
          // for the purposes of the this blog.
          uriTemplate.match(uri, parameters);
          System.out.println(parameters);
          parameters.put("name","Arnold");
          parameters.put("age","110");
  
          UriBuilder builder = UriBuilder.fromPath(template);
          URI output = builder.build(parameters);
          System.out.println(output.toASCIIString());
  
  
      }
  }
  </code></pre>
  
  <p>but when I compile the code it gives me this error </p>
  
  <blockquote>
    <p><code>Exception in thread "main" java.lang.IllegalArgumentException: The template variable 'age' has no value</code></p>
  </blockquote>
  
  <p>Please help me out to fix this, (may be my imports are causing the issue)</p>