Start and stop a context without Manager?

Greg Huber <[email protected]>
Newsgroups gmane.comp.jakarta.tomcat.user
Message-ID <[email protected]>
Hello,

A while back this thread was posted here and it works great on my local 
dev box (using a background thread) using vhost="localhost/".  When I 
deploy it as a war the vhost name changes.

 From the output:

Attributes for object: Catalina:j2eeType=Servlet,WebModule=//localhost/##914-develop,name=MyServlet,J2EEApplication=none,J2EEServer=none:

How do I reliably get the vhost / WebModule name when using a war?

The attribute "org.apache.catalina.webappVersion" gives "914-develop" 
but its missing the ##

My war is called: ROOT##914-develop.war

Thanks

On 16/10/2025 18:02, Christopher Schultz wrote:
> I recently added reload capabilities to my application for users with 
> admin roles. The code is basically (after triple-checking 
> authentication and some app-specific bells and whistles):
>
>         ServletContext app = getServletContext();
>
>         MBeanServer mbs = getServer();
>         if(null != mbs) {
>             try {
>                 String vhost = getHostname();
>
>                 ObjectName objectName = new 
> ObjectName("Catalina:j2eeType=WebModule,name=//" + vhost + 
> app.getContextPath() + ",J2EEApplication=none,J2EEServer=none");
>
>                 if(mbs.isRegistered(objectName)) {
>                     mbs.invoke(objectName, "reload", null, null);
>                 }
>             } catch (MBeanException | MalformedObjectNameException | 
> InstanceNotFoundException | ReflectionException e) {
>                 app.log(getClass().getSimpleName() + ": Failed to 
> reload application ", e);
>             }
>         }
>
> ... with the helper functions:
>
>
>     private String hostname = "localhost"; // This is an init-param
>
>     public String getHostname() {
>         return hostname;
>     }
>
>     private static MBeanServer getServer() {
>         ArrayList<MBeanServer> mbservers = 
> MBeanServerFactory.findMBeanServer(null);
>
>         if (mbservers.size() > 0) {
>             MBeanServer mbserver = mbservers.get(0);
>
>             if (mbserver != null)
>                 return mbserver;
>         }
>
>         return null;
>     }
>
> Just wire this into your application somewhere. You don't need to 
> install anything else, even the Manager application.
>
> -chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.