如何在嵌入式tomcat中使用classpath中的html / css / js / jsp文件

时间:2014-04-30 12:45:50

标签: java jsp tomcat embedded-tomcat-7

我有一个像这样配置的emebbed tomcat服务器

package engine.server.http;

import java.io.File;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.jconfig.Configuration;
import org.jconfig.ConfigurationManager;

import static kic.engine.util.factory.LogFactory.*;

public class EmbeddedTomcat {
    private static final Configuration config = ConfigurationManager.getConfiguration();
    private static final int httpPort = config.getIntProperty("http-port", 8881, "server");
    private Tomcat tomcat = new Tomcat();

    public static void main(String[] args) throws Exception {
        EmbeddedTomcat ebt = new EmbeddedTomcat();
        ebt.start();
        ebt.getTomcat().getServer().await();
    }

    public void start() {
        String webappDirLocation = "src/main/webapp/";
        String webAppFullPath = new File("./" + webappDirLocation).getAbsolutePath();

        tomcat.setPort(httpPort);


        INFO("configuring app with basedir: ${1}", webAppFullPath);
        try {
            tomcat.addWebapp("/", webAppFullPath);
            tomcat.start();
        } catch (Exception ex) {
            ERROR("failed to start tomcat! ${1}", ex);
        }
    }

    public void shutdown() {
        try {
            tomcat.stop();
        } catch (LifecycleException ex) {
            ERROR("failed to shutdown tomcat! ${1}", ex);
        }
    }

    public Tomcat getTomcat() {
        return tomcat;
    }
}

但是如何在我的类路径中使用jsp,css,js和html文件而不是webroot“src / main / webapp /”?

0 个答案:

没有答案