user2281439
user2281439

Reputation: 693

Embedded Jetty server

I have some project which I build with jetty. I create server from code like

    Server server = new Server(8082);
    server.setHandler(new DefaultRequestHandler());
    server.start();
    server.join();

It's very useful when develop app, but is the proper way to deploy such app to server? I can build a jar from it and run it as

    java -jar server.jar

Is it ok or I should install jetty and deploy my app as war? The problems I have with running simple jar is that I deploy it remote machine, and if I run it as type it will run in main thread in console, so I can't do anything in that console window. If I close console window it will kill the process. I can start it as

    java -jar server.jar &

And it will go to background, but I have no way to stop server than. Only with kill command. Also I find there is some start.jar which can start jetty, but I did not found descriptive examples when and how exactly use it.

And second problem I have is with logs. It prints all the logs to console or to /dev/null. Is there a way to handle log files somehow? I mean to have possibility store log for 3 days for example, and not write log in one file till space will end or while I'll manually delete log file. Does this handles server, or some logs libs such as log4j or something other?

I use centos7 as server.

Upvotes: 0

Views: 520

Answers (2)

Koziołek
Koziołek

Reputation: 2874

There is a ready embedded jetty server jar called jetty-runner.jar. It could be a very nice solution. At this moment I found only one minus of this package. If you need support to web sockets you must repack it with additional jars.

Upvotes: -1

kamoor
kamoor

Reputation: 2939

This is perfectly ok. It is a very common practice to use embedded application server containers especially when we move more towards micro services. Everything is managed by build, easy to build/deploy and maintain.

Your problem with maintaining runtime as a service is answered here for windows. For *nix you can follow this command

java -jar abc.jar &

About handling log,

It is better to handle logs at application itself. Log4j will be a good framework to configure logging level, rotation schedule.

If you have libraries printing output to console, it can be redirected to a log file. Then you need to configure logrotate which is available almost all *nix flavors.

Upvotes: 0

Related Questions