I\'m trying to implement a REST Server API using Java-ee following this tutorial. Instead of Glassfish, I use Tomcat.
I could develop a servlet
@WebServ
"Instead of Glassfish, I use Tomcat."
Look at this
javax
javaee-api
7.0
This is nothing more than basically a bunch of interfaces for the EE spec. There is no implementation. Java EE servers will have the implementation. Tomcat is not an EE server. The only part of the EE spec it will definitely implements is the Servlet Specification. You are trying to work with the JAX-RS spec, where Tomcat for sure by default does not have an implementation for. So you need to add that implementation.
The easiest IMO to get started with, is Jersey. You can simple add this dependency
org.glassfish.jersey.containers
jersey-container-servlet
2.17
And it will get you up and running. Keep the Jersey User Guide handy. It will come in use.
Also I don't know what JsonArray
is, but what will happen when you run this is you will get some error similar to "No MessageBodyWriter found for JsonArray and media type application/json". You need to provider. If you are going to use the Java EE JSONP API, then you should add the this provider
org.glassfish.jersey.media
jersey-media-json-processing
2.17
As you get to working alot with JSON, you wil find this API to be difficult to maintain. I'd recommend using Jackson. If you don't already know it, I'd suggest learning it. It offers simple POJO to JSON mapping. For Jackson, you can add this dependency
org.glassfish.jersey.media
jersey-media-json-jackson
2.17