Tomcat(8081端口)下通过Mbeans/JMX启停Web应用报错的解决办法
Hey there, let's get this sorted out for you. The javax.management.InstanceNotFoundException error you're hitting is mainly due to two mismatches between your code and your Tomcat setup (the non-default 8081 port) and how Tomcat registers web app MBeans. Here's exactly what you need to modify:
1. Update the JMX Connection Address (If Applicable)
If your code uses an HTTP-based JMX proxy (like accessing Tomcat's manager JMX endpoint) or a remote JMX connection, swap the default 8080 port with your actual Tomcat port 8081:
- For HTTP proxy: Change the endpoint URL from
http://localhost:8080/manager/jmxproxytohttp://localhost:8081/manager/jmxproxy - For remote JMX connection: If you’ve configured a dedicated JMX remote port in
catalina.sh/catalina.bat(viacom.sun.management.jmxremote.port), ensure you’re using that correct port (note: this is usually different from your HTTP port 8081)
2. Fix the MBean ObjectName
This is the core issue behind your exception. Tomcat registers web app MBeans with a name attribute that includes the full URL of the app—since your Tomcat runs on 8081, your original ObjectName misses this port number.
Your original ObjectName:
Catalina:J2EEServer=none,name=//localhost/adapaconsole,J2EEApplication=none,j2eeType=WebModule
Replace it with this corrected version:
Catalina:J2EEServer=none,name=//localhost:8081/adapaconsole,J2EEApplication=none,j2eeType=WebModule
The key change is adding :8081 after localhost in the name property—this matches how Tomcat registers your adapaconsole app’s MBean, so your code will finally locate the correct instance.
3. Verify User Permissions
Just to rule out extra hurdles, make sure your Tomcat user (configured in tomcat-users.xml) has the manager-jmx role assigned. Without this, you might hit permission errors even after fixing the above:
<user username="your-jmx-user" password="your-password" roles="manager-jmx"/>
After making these adjustments, your code should successfully locate the adapaconsole app’s MBean and let you start/stop/reload it without restarting Tomcat.
内容的提问来源于stack exchange,提问作者Anuj

