简体   繁体   中英

How to deploy java jersey and Grizzly on Windows Server

I have developed jersey web service server on mac os x. I have been testing by running it using maven command line: mvn exec:java and it works just fine. I'm currently running my web services in grizzly.

Now i would need to deploy to Windows Server 2008. What should I do?

I have been reading the deployment documentation on jersey here .

  1. Do I need to follow section 4.2(JAX-RS Application Model) to 4.4(Configuring the Classpath Scanning)?
  2. Do i just run the maven command line in windows? ie: mvn exec:java
  3. Do I need to compile into a jar file? I have tried compiling into jar file but I encounter errors.

This is how I compiled the jar file: mvn -Dmaven.test.skip=true package
This is how i ran the jar file: java -jar application.jar . Here is the error:

MyName-MacBook-Pro:target myname$ java -jar application-1.0-SNAPSHOT.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/grizzly/http/server/HttpServer at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2531) at java.lang.Class.getMethod0(Class.java:2774) at java.lang.Class.getMethod(Class.java:1663) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) Caused by: java.lang.ClassNotFoundException: org.glassfish.grizzly.http.server.HttpServer at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassL oader.loadClass(ClassLoader.java:358) ... 6 more

Here is the content of my pom.xml:

http://maven.apache.org/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion> <groupId>org.company</groupId> <artifactId>application</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>application</name> <dependencyManagement> <dependencies> <dependency> <groupId>org.glassfish.jersey</groupId> <artifactId>jersey-bom</artifactId> <version>${jersey.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-grizzly2-http</artifactId> </dependency> <!-- uncomment this to get JSON support: <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> </dependency> --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.9</version> <scope>test</scope> </dependency> <!-- Gson: Java to Json conversion --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.2.4</version> <scope>compile</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <!-- Apache Log4J --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <inherited>true</inherited> <configuration> <source>1.7</source> <target>1.7</target> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib</classpathPrefix> <mainClass>org.company.Main</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>org.company.Main</mainClass> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>org.company.Main</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> <properties> <jersey.version>2.7</jersey.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project> 

You need to use the Apache Maven Shade Plugin (or a similar plugin) to build your Uber Jar (a jar with all dependencies included). Then take this jar to your server and run with:

java -jar bla.jar PATH_TO_POSSIBLE_CONFIG_FILE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM