2013/1/29 Jimmy Johnson <eclectic.sou...@gmail.com>: > System: Mac OS X 10.8 > Tomcat Version: 7.0.30 > Language: Java > > I'm trying to set up the context in an embedded Tomcat instance to serve > files from a local directory not within the deployed folder. > > In the standard server.xml when using the standard Tomcat configuration I > have this: > > <Context docBase="/MyWebApp/images" path="/tmp/images/" > reloadable="false"/> > > and it works great. > > I have tried different variations on the following tomcat embedded call > without success: > > tomcat.addContext(tomcat.getHost(), "/MyWebApp/images", > "/documents/images/"); > > I also tried: > > tomcat.addContext("/MyWebApp/images", "/documents/images/"); > > It seems that Tomcat does see the external docBase folder I have specified > because if I specify a path that doesn't exist it complains. It also see's > the context mapping because hitting the "/MyWebApp/images" filters out the > request before it hits the spring security filters I have in place and > reports a 404 file not found. > > I am planning on looking at the source this evening and seeing if I can > track down the file path it is looking at, but I thought someone here might > know of a solution. > > It looks like this grails question was along the same lines: > > http://stackoverflow.com/questions/8332851/grails-add-context-to-embedded-tomcat-in-development > > But im not using grails. > > Here is the full startup code I am using: > > package launch; > import java.io.File; > import org.apache.catalina.startup.Tomcat; > 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)); > tomcat.addWebapp("/MyWebApp", new > File(webappDirLocation).getAbsolutePath()); > tomcat.addContext("/MyWebApp/images", "/tmp/images/");
The above two lines. You already know the "addWebapp" method, so why are you trying to use "addContext"? > tomcat.start(); > tomcat.getServer().await(); > } > } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org