Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use Context.setSessionTimeout(int). Java docs <a href="http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/Context.html#setSessionTimeout%28int%29" rel="nofollow">here</a>. Here's the same Main class with a session timeout set to 30 days:</p> <pre><code>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(); } } </code></pre> <p>Notice the <code>Context ctx = ...</code> and <code>ctx.setSessionTimeout(...)</code>.</p> <p>As for Tomcat Manager, you can't use it when you embed Tomcat in your application this way. I am curious what you would like to use Tomcat Manager for?</p> <p>Anything you would normally do from <code>server.xml</code> you can do via the embed API. The whole point of embedding is that you configure everything programmatically.</p> <p>You can still set up your own <code>web.xml</code> as you normally would. Just add it in a <code>WEB-INF</code> directory under the directory you pass in as <code>webappDirLocation</code>. But again, I am curious what you would want to put in <code>web.xml</code>? Because you "own" the main application loop, you can set up any configuration you need from your main method. I highly recommend a practice of initializing everything you need in the main loop and reading OS environment variables for anything that is environment specific (e.g. a JDBC url).</p> <p>Finally, as for Eclipse, you don't need hot deploy anymore because you are not using a container deployment model. You can simply run your application from inside Eclipse with "Debug as..." and Eclipse will auto compile and reload code as you change it. It's not exactly similar to hot deploy. For example, it won't hot reload classes with new method signatures. But it's much faster to cycle the whole app compared to when using a container, so overall, I find it much more productive.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload