0

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.

user2281439
  • 603
  • 1
  • 11
  • 18

2 Answers2

0

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.

Community
  • 1
  • 1
kamoor
  • 2,769
  • 2
  • 16
  • 32
-1

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.

Koziołek
  • 2,570
  • 25
  • 37
  • jetty-runner.jar is *NOT* an embedded jetty server. It is a testing and QA only convenience to execute the most bare boned and simplistic *NON-PRODUCTION* environments to get people comfortable with Jetty and eventually move into the distribution (which *USES* a proper Jetty Embedded setup via XML) or a true Jetty Embedded of your own design. – Joakim Erdfelt Dec 26 '14 at 12:56
  • so if it not production ready solution then why Heroku recommends it as one of servers for java apps? – Koziołek Dec 26 '14 at 14:14
  • Lots of bad information on the internet. Heroku isn't alone in this. JBoss/Weld also make some horrific recommendations as well (resulting in a giant security holes). – Joakim Erdfelt Dec 26 '14 at 16:25