0

How can I we deploy a web service in Java by building a JAR or a WAR?

This part of my application is a REST web services with Jersey, Maven and Eclipse (part of a N-tier achitecture: Client-> Made with a game engine named Godot ,WebServices REST and a MySQL database).

I recently converted it to a web dynamic project but i was wondering if my webservice application really needed to be converted to a dynamic web project to be able to deploy it (with Tomcat)?

I use the HttpServer class to create a server. Everything works fine when I work locally, but how can I make it work when I deploy it if I don't convert it to a dynamic web project? This means with a JAR file when I build it. Do I need to combine both WebressourceLaucher i create with HttpServer and the dynamic web project (see below)?

This is how I was taught to do it:

My WebressourceLaucher class:

https://gyazo.com/e70f0c122b3ed76b7b669a36aa7bd0be

Here the structure of the project: https://gyazo.com/8586b375113bad19753fe5526479cc44

Here my pom.xml to have more details about the project

https://sharemycode.fr/870

Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118
romainSB
  • 1
  • 1
  • You don't need to convert it to a dynamic web project, as long as you produce a `WAR` with the [maven-war-plugin](https://maven.apache.org/plugins/maven-war-plugin/). It just informs Eclipse of the nature of your project and gives some additional tools/features for working in Eclipse. If you build an executable JAR, you have to start it per command line. – Sascha Jun 10 '21 at 08:36
  • If you just need an installer, you could have a look at my answer here: https://stackoverflow.com/q/67907952/2135838 – Sascha Jun 10 '21 at 08:42
  • Thank you for your answer i choose to build an executable JAR the webservice is lauching but it seems that when i build eclipse does not include hibernate.cfg.xml in the jar file. i get this : juin 10, 2021 11:33:04 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException GRAVE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml] any idea – romainSB Jun 10 '21 at 10:54
  • Well, if you start your application in Eclipse, Eclipse builds the classpath for you and includes all the maven dependencies etc. To build an executable jar with maven you have to do a bit more than just create a jar. Please work through [this tutorial](https://www.baeldung.com/executable-jar-with-maven). – Sascha Jun 10 '21 at 12:16
  • Thank you again you are very helpful i choose Apache Maven Assembly Plugin solution i dont know if it's related but i get this error : – romainSB Jun 11 '21 at 10:25
  • PM com.sun.jersey.spi.container.ContainerResponse write GRAVE: A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/json was not found. i try to find solutions i check if i had good dependencies like jersey-json but nothing change – romainSB Jun 11 '21 at 10:59
  • Search for the error message. For instance it could be [this](https://stackoverflow.com/a/20122256/2135838), but it could be any of the other solutions. – Sascha Jun 11 '21 at 13:07

0 Answers0