Tomcat: JMX is used to supervise Tomcat in several ways.

Source: Internet
Author: User
Tags jconsole

Tomcat: JMX is used to supervise Tomcat in several ways.

Tomcat uses the JMX management method. The built-in Application manager of Tomcat uses the JMX method to manage Tomcat, so as to achieve dynamic deployment, start, and stop of Web applications.

However, a manager application uses the JMX interface locally. What do other remote clients do?

 

Method 1: JConsole client:

1) set the environment variable CATALINA:

set CATALINA_OPTS=-Dcom.sun.management.jmxremote  -Dcom.sun.management.jmxremote.port=9999  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false

This is the setting method for Windows.

Linux/Unix: export CATALINA_OPTS =-Dcom. sun. management. jmxremote '''catalina _ OPTS =-Dcom. sun. management. jmxremote '''catalina _ OPTS =-Dcom. sun. management. jmxremote ''-Dcom. sun. management. jmxremote. authenticate = false

Many people on the Internet say that JAVA_OPTS is set up. We recommend that you do not do this.

2) start Tomcat

3) Open JConsole and set the remote connection address: tomcat_ip: 9999.

Tomcat_ip is the IP address of the machine where Tomcat is located and 9999 is the port set above.

 

Method 2: Use Ant build. xml

For more information, see: http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#JMXAccessorGetTask:__get_attribute_value_Ant_task

Same principle.

 

Method 3: Use Ant Task in Java code

GetTask task=new GetTask();task.setURL("http://tomcat_ip:9999/manager");task.setUser("xxx");task.setPassword("xxx");Project pro=new Project();task.setOutproperty("output");task.setProject(pro);task.execute();String responseText=project.getProperty("output");

Principle: Use a url to access the manager application and use JMX for manager Management.

 

Method 4: Access the manager application directly in Java code

public void tomcatHome(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        URL url=new URL("http://localhost:8080/manager/html");        HttpURLConnection  conn=(HttpURLConnection)url.openConnection();                conn.setAllowUserInteraction(false);        conn.setDoInput(true);        conn.setUseCaches(false);                conn.setDoOutput(false);        conn.setRequestMethod("GET");                conn.setRequestProperty("Accept-Charset", "utf-8");        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");                String username="admin";        String password="admin";        String authoInfo=new String(Base64.encode((username + ":" + password).getBytes()));        conn.setRequestProperty("Authorization", "Basic "+authoInfo);        conn.setRequestProperty("Connection", "keep-alive");        conn.connect();                InputStream input=conn.getInputStream();        response.setContentType("text/html;charset=UTF-8");        PrintWriter out= response.getWriter();        byte[] bs=new byte[1024];        int len=-1;                while((len=input.read(bs))!=-1){            out.write(new String(bs, 0, len));        }        out.flush();        out.close();            }

Same principle.

 

Method 5: access through JMX APIs in Java

See my previous blog. Of course, this method is also common on the network.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.