Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 3.6 KB

README.md

File metadata and controls

68 lines (46 loc) · 3.6 KB

Maven build status

Simple Jersey 2 example

Simple jersey 2 start application with president example database - used for Project at Fontys Venlo.

This example is just a start, this means, no detailed explanations will be given as well as no ready implementation. It is also not mandatory to do it like this.

The structure is as follows:

  • You use a docker container for the database. The same thing as last semester, but now we will create an own docker container for that based on the postgres container.
    • why? Because we want to have the database be filled already with our testdata, in this case the president database. Nice, right?
  • Then you run the application locally via jetty on your machine and this connect with the postgres database on your docker container

Howto run

  • clone first (if you want to use it as base for your project, use this as a template, see button above near cloning button)
  • build your own docker container based on the Dockerfile. Have a look into it how it works.
docker build -t mydbimage:0.1 .
  • you now created an own image which is installed locally on your machine. Look it up by typing docker images in your terminal. You should see it.
  • Now run your own image:
docker run -d -p 5432:5432 --name myprj2database mydbimage:0.1

Et voilà, you have a running REST-Api Backend-example.

You can take this as a starting point for your project 2.

Important

  • You can use this as base for your own application. Note that you should put your SQL files into sql-files folder, have a look into the already existing files (which are from databases 1 course). The databae will be created with your schema and filled with your data.
  • If you change your pre-filled database sql files, you need to (re)-create your database image and e.g. give it a new version, e.g.:
docker build -t mydbimage:0.2 .

You can choose freely how you name you images (e.g. mydbimage or superimage) and the version tags (e.g. 0.1, 0.2, 1.0... ) Advise is to stick to normal version numbers.

  • The java application has already the correct connection parameters set up for connecting with the database, but only if you did everything like described above. If you change the passwords in the Dockerfile, of course you need to adapt it.

  • Note: it could be that you have to clean your application mvn clean or use mvn clean jetty:run

Have fun and feel free to change for your project purpose

Ideas

  • if you understand fully what was done here, you can deploy as well the java application as war to docker if you like.
  • further, you could use Docker compose for running all services with one command.

Useful links and tutorials regarding REST-API with Jersey 2.x

Optional, integrate Swagger UI