How to start and stop an Tomcat container with Java?

后端 未结 4 609
野的像风
野的像风 2020-12-16 01:13

I have a Maven project that starts a tomcat container for pre-integration-tests (jUnit Tests). Most of my tests require that the web-application under tests is restarted. So

4条回答
  •  -上瘾入骨i
    2020-12-16 01:45

    I'm using follow method:

    private static final String TOMCAT = "D:/test_tomcat";
    @BeforeClass
    public static void runTomcat() {
        bootstrap = new Bootstrap();
        bootstrap.setCatalinaHome(TOMCAT);
        try {
            bootstrap.start();          
        } catch (Exception e) {
            e.printStackTrace();
            fail("Не удалось запустить Tomcat");
        }
    }
    
    @AfterClass
    public static void stopTomcat() {
        try {
            bootstrap.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    But is method have a one problem - I need copy WAR file in 'webapps' directory every time have change source code. I thing what copy my class from classpath in web-inf and copy 'jar' from classpath in web-inf/lib.

提交回复
热议问题