First, modify pom. xml:
[Plain]
<Dependency>
<GroupId> com. sun. jersey </groupId>
<ArtifactId> jersey-server </artifactId>
<Version >$ {jersey-version} </version>
</Dependency>
<Dependency>
<GroupId> com. sun. jersey </groupId>
<ArtifactId> jersey-grizzly2 </artifactId>
<Version >$ {jersey-version} </version>
<Scope> compile </scope>
</Dependency>
[Plain]
<Properties>
<Jersey-version> 1.15 </jersey-version>
</Properties>
Second, the Main. java imported package is as follows:
[Plain]
Import com. sun. jersey. api. container. grizzly2.GrizzlyServerFactory;
Import com. sun. jersey. api. core. PackagesResourceConfig;
Import com. sun. jersey. api. core. ResourceConfig;
Import java. io. IOException;
Import java.net. URI;
Import javax. ws. rs. core. UriBuilder;
Import org. glassfish. grizzly. http. server. HttpServer;
The code must be modified as follows:
[Plain]
Public class Main {
Private static int getPort (int defaultPort ){
// Grab port from environment, otherwise fall back to default port 9998
String httpPort = System. getProperty ("jersey. test. port ");
If (null! = HttpPort ){
Try {www.2cto.com
Return Integer. parseInt (httpPort );
} Catch (NumberFormatException e ){
}
}
Return defaultPort;
}
Private static URI getBaseURI (){
Return UriBuilder. fromUri ("http: // localhost/"). port (getPort (9998). build ();
}
Public static final URI BASE_URI = getBaseURI ();
Protected static HttpServer startServer () throws IOException {
System. out. println ("Starting grizzly ...");
ResourceConfig rc = new PackagesResourceConfig ("com. esri ");
Return GrizzlyServerFactory. createHttpServer (BASE_URI, rc );
/*
Final Map <String, String> initParams = new HashMap <String, String> ();
InitParams. put ("com. sun. jersey. config. property. packages", "com. esri ");
System. out. println ("Starting grizzly2 ...");
Return GrizzlyWebContainerFactory. create (BASE_URI, initParams );
*/
}
Public static void main (String [] args) throws IOException {
// Grizzly 2 initialization
HttpServer httpServer = startServer ();
System. out. println (String. format ("Jersey app started with WADL available"
+ "% Sapplication. wadl \ nHit enter to stop it ...",
BASE_URI ));
System. in. read ();
HttpServer. stop ();
}
}
The comments in the startServer function are the old code generated by the wizard.
Okay. Start it again. Everything is normal.