
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.sun.grizzly.http.SelectorThread;
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;

public class Main {
    public static void main(String[] args) throws IOException {
        
        final String baseUri = "http://localhost:"+(System.getenv("PORT")!=null?System.getenv("PORT"):"9998")+"/";
        final Map<String, String> initParams = new HashMap<String, String>();

        initParams.put("com.sun.jersey.config.property.packages","resources");
        
        System.out.println("Starting grizzly...");
        SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
        System.out.println(String.format("Jersey started with WADL available at %sapplication.wadl.",baseUri, baseUri));
    }
}

@@ -1,218 +1,283 @@
-%0A
 import 
-java.io.IOException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport com.sun.grizzly.http.SelectorThread;%0Aimport com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;%0A%0Apublic class Main %7B
+com.sun.jersey.api.container.grizzly.GrizzlyServerFactory;%0Aimport com.sun.jersey.api.core.PackagesResourceConfig;%0A%0Aimport javax.ws.rs.core.UriBuilder;%0Aimport java.io.IOException;%0Aimport java.net.URI;%0A%0Apublic class Main %7B%0A%0A    private static final int DEFAULT_PORT = 9998;%0A
 %0A   
@@ -349,61 +349,142 @@
     
+GrizzlyServerFactory.create(getBaseUri(), getResourceConfig());
 %0A    
+%7D%0A%0A
     
-final String baseUri = %22http://localhost:%22+(
+private static URI getBaseUri() %7B%0A        final int port = 
 Syst
@@ -504,15 +504,36 @@
 RT%22)
+ 
 !=
+ 
 null
-?
+ ? Integer.parseInt(
 Syst
@@ -553,454 +553,225 @@
 RT%22)
-:%229998%22)+%22/%22;%0A        final Map%3CString, String%3E initParams = new HashMap%3CString, String%3E
+) : DEFAULT_PORT;%0A        return UriBuilder.fromUri(%22http://localhost/%22).port(port).build
 ();%0A
-%0A
     
+%7D%0A%0A
     
-initParams.put(%22com.sun.jersey.config.property.p
+private static P
 ackages
-%22,%22r
+R
 esource
-s%22);%0A        %0A        System.out.println(%22Starting grizzly...%22);%0A        SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);%0A        System.out.println(String.format(%22Jersey started with WADL available at %25sapplication.wadl.%22,baseUri, baseUri)
+Config getResourceConfig() %7B%0A        return new PackagesResourceConfig(%22resources%22
 );%0A 

Simplify server start in main method