Run non java web application on tomcat

I have a simple Java application that I need to run at any time (also to start automatically when the server reboots).
I thought of a maintenance shell, but the Windows version is paid.
Is there a way I can configure Tomcat to run a specific class from a project automatically, or any other solution that could give the same result?

+5
source share
3 answers

I think your need is to have an application (regardless of the Internet or not a website) that starts with tomcat at the same time.

, -, ( , tomcat) .

web.xml, :

<listener>
        <description>application startup and shutdown events</description>
        <display-name>ApplicationListener</display-name>
        <listener-class>com.myapp.server.config.ApplicationListener</listener-class>
</listener>

ApplicationListener ServletContextListener. :

import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;



/**
 * Class to listen for application startup and shutdown
 * 
 * @author HBR
 * 
 */
public class ApplicationListener implements ServletContextListener {
    private static Logger logger = Logger.getLogger(ApplicationListener.class);

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        logger.info("class : context destroyed");

    }

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext context = servletContextEvent.getServletContext();
        ///// HERE You launch your class
        logger.info("myapp : context Initialized");
    }



}
+4

google :

, Tomcat ( -), - Quartz Scheduler.

0

Take a look:

Both will help you launch a Java application as a service. If you want to launch a couple of your application using tomcat, you can implement your own simple web application that launches your application. you can use

  • which starts when the server starts (configure this in web.xml)
  • HTTP filter
  • servlet context.
0
source

All Articles