Heroku 修改嵌入式tomcat webapp的配置
我一直在尝试修改heroku应用程序的嵌入式tomcat配置。我已经使用下面的wiki链接安装了heroku应用程序,该链接配置了一个简单的嵌入式tomcat 源代码如下:Heroku 修改嵌入式tomcat webapp的配置,heroku,tomcat7,Heroku,Tomcat7,我一直在尝试修改heroku应用程序的嵌入式tomcat配置。我已经使用下面的wiki链接安装了heroku应用程序,该链接配置了一个简单的嵌入式tomcat 源代码如下: public static void main(String[] args) throws Exception { String webappDirLocation = "src/main/webapp/"; Tomcat tomcat = new Tomcat(); //The port th
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
//The port that we should run on can be set into an environment variable
//Look for that variable and default to 8080 if it isn't there.
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8080";
}
tomcat.setPort(Integer.valueOf(webPort));
tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
问题:
autodeploy=true
,使我不必在每次修改java代码时编译并重新启动应用程序Kiran使用Context.setSessionTimeout(int)。Java文档。下面是会话超时设置为30天的同一个主类:
package launch;
import java.io.File;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.Context;
public class Main {
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
//The port that we should run on can be set into an environment variable
//Look for that variable and default to 8080 if it isn't there.
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8080";
}
tomcat.setPort(Integer.valueOf(webPort));
Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
ctx.setSessionTimeout(2592000);
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
}
请注意上下文ctx=…
和ctx.setSessionTimeout(…)
至于Tomcat管理器,当您以这种方式将Tomcat嵌入应用程序时,您不能使用它。我很好奇你想用Tomcat Manager做什么
通常从server.xml
执行的任何操作都可以通过嵌入API执行。嵌入的全部要点是以编程方式配置所有内容
您仍然可以像平常一样设置自己的web.xml
。只需将它添加到作为webappDirLocation
传入的目录下的WEB-INF
目录中。但我还是很好奇,您想在web.xml
中添加什么?因为您“拥有”主应用程序循环,所以您可以从主方法设置所需的任何配置。我强烈建议您在主循环中初始化所需的所有内容,并读取操作系统环境变量中与环境相关的任何内容(例如JDBCURL)
最后,对于Eclipse,您不再需要热部署,因为您没有使用容器部署模型。您只需在Eclipse内部使用“Debug as…”运行应用程序,Eclipse将在您更改代码时自动编译和重新加载代码。它与热部署并不完全相似。例如,它不会用新的方法签名重新加载类。但与使用容器相比,循环整个应用程序要快得多,所以总体而言,我发现它的效率要高得多。会话超时只是在web.xml中配置的,对吗?使用web.xml进行应用程序配置不应随嵌入的tomcat而改变。