How to stop only one app?

2019-08-04 06:56发布

问题:

Jetty is running 3 sites from webapps. On of which is a "static" angular site, another is a huge java app.

Typically, I use Ctrl + c to stop Jetty, make changes on my angular site, and start Jetty with

java -jar start.jar -DCommon.properties.path=C:\Jetty

If I try to edit the files while Jetty is running, random, buggy code is injected, breaking the site.

So this process is extremely tedious. The java app takes 15-20 seconds to load. So if I forget a slash, it takes about a min to shut it down and restart it.

Is there a way I can just stop/start only one of the webapps instead of all 3 at once?

回答1:

You seem to be using Windows.

The problems you are having relate to the traditionally wonky FileSystem locking behavior that is unique to Microsoft Windows (no other OS that runs Java does this)

See official documentation about it at https://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html

If you follow the advice laid out in that documentation then you'll not need to stop/start a specific webapp.

Important: Note that the advice in the documentation is for DEVELOPMENT TIME ONLY and is not a good general configuration for production.


Insert from OP:

I followed the directions in the docs above, and it worked! Here's what I did:

  1. Find your webdefault.xml file.

    • Mine was in C:\Place_where_Jetty_was_installed\Jetty\etc\
  2. Open it and search for UseFileMappedBuffer

  3. Find this: <init-param> <param-name>useFileMappedBuffer</param-name> <param-value>true</param-value> </init-param>

  4. Set param-value to false <param-value>false</param-value>

That being said, if you still want to go down this path, there's 2 ways ...

1. Use hotreload

Create an XML deployable for your "reload" webapp and touch it to hot reload just that 1 webapp.

The File: ${jetty.base}/webapps/myapp.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
          "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/myapp</Set>
  <Set name="war"><Property name="jetty.webapps"/>myapp.war</Set>
</Configure>

Then to make jetty reload it just ...

$ touch /path/to/myjettybase/webapps/myapp.xml

This standard Posix command will update the timestamp of that file, which will be seen by Jetty as "hey, that file updated, I must reload it"

2. Use JMX to stop/start a specific webapp

Start Jetty with the JMX module active (--module=jmx).

Start a JMX console (the JDK ships with jmc and jconsole) and connect to your running Jetty instance. Find the MBean for your specific webapp and use the stop() and start() commands on that specific webapp.



标签: Jetty