웹/Java
tomcat 서버 메인 함수
임풀
2019. 9. 29. 20:38
반응형
기본 포트로 8080 사용, webapp 폴더를 루트 디렉토리로 사용한다.
|
import java.io.File;
public class WebServerLauncher {
public static void main(String[] args) throws Exception {
String webappDirLocation = "webapp/";
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8080";
}
tomcat.setPort(Integer.valueOf(webPort));
Connector connector = tomcat.getConnector();
connector.setURIEncoding("UTF-8");
tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
tomcat.getServer().await();
}
}
|
반응형