Tips for Java EE using Tomcat and Jersey for Restful webservices

0
933
Java Programming
  1. Download Tomcat from http://tomcat.apache.org/ and be sure to pick the one just before alpha or beta ie the stable version
  2. Pick the Zip version.  that is the one that you want as it is not tied to starting as a service that the rest of them do like the win64 version.
  3. Extract files to the fastest drive ie your Solid State Disk.  usually a good approach is like c:\tools\apache
  4. if you are using Jersey then run the maven archetype off the command line
    1. with prompts: mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactid=jersey-quickstart-webapp -DarchetypeVersion=2.2
    2. without prompts: mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp  -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.scq -DartifactId=example-services -Dpackage=com.example -DarchetypeVersion=2.2
    3. once done you can do a file >> import  >> maven >> existing maven project
  5. If you connect to a database eg UcanaccessDriver then you must put the files in the WEB-INF/lib directory for Tomcat to load the drivers if you want it to run in the container.
  6. Jersey can manage Level2 maturity using HTTP verbs but using JAXB under the hood to do the marshalling to XML and we set the xmlRootElement
  7. Jersey using the jersey-media-moxy in the POM.xml to produce json output formats. A precursor to the json is the XML fomat created from JAXB then that is converted to json by the jersey-media-moxy