|
package com.zrlog.web; |
|
|
|
import com.zrlog.common.Constants; |
|
import org.apache.catalina.LifecycleException; |
|
import org.apache.catalina.startup.Tomcat; |
|
|
|
import javax.servlet.ServletException; |
|
import java.io.File; |
|
|
|
public class Application { |
|
|
|
public static void main(String[] args) throws LifecycleException { |
|
String webappDirLocation; |
|
if (Constants.IN_JAR) { |
|
webappDirLocation = "webapp"; |
|
} else { |
|
webappDirLocation = "src/main/webapp/"; |
|
} |
|
|
|
Tomcat tomcat = new Tomcat(); |
|
|
|
String webPort = System.getenv("PORT"); |
|
if (webPort == null || webPort.isEmpty()) { |
|
webPort = "8080"; |
|
} |
|
|
|
|
|
|
|
tomcat.setPort(Integer.parseInt(webPort)); |
|
tomcat.getConnector(); |
|
|
|
|
|
|
|
File additionWebInfClasses; |
|
if (Constants.IN_JAR) { |
|
additionWebInfClasses = new File(""); |
|
} else { |
|
additionWebInfClasses = new File("target/classes"); |
|
} |
|
|
|
tomcat.setBaseDir(additionWebInfClasses.toString()); |
|
|
|
if (!Constants.IN_JAR && !new File("").getAbsolutePath().endsWith(File.separator + "web")) { |
|
webappDirLocation = "web/" + webappDirLocation; |
|
} |
|
tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath()); |
|
tomcat.start(); |
|
tomcat.getServer().await(); |
|
} |
|
} |
|
|