Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 61581 invoked from network); 30 Apr 2009 19:57:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Apr 2009 19:57:33 -0000 Received: (qmail 14829 invoked by uid 500); 30 Apr 2009 19:57:28 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 14785 invoked by uid 500); 30 Apr 2009 19:57:28 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 14774 invoked by uid 99); 30 Apr 2009 19:57:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2009 19:57:27 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of marcel@frightanic.com does not designate 212.101.4.135 as permitted sender) Received: from [212.101.4.135] (HELO mail01.solnet.ch) (212.101.4.135) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2009 19:57:16 +0000 X-Virus-Scanned: by SolNet-Check at mail01.solnet.ch Received: from mail01.solnet.ch ([127.0.0.1]) by localhost (mail01.solnet.ch [127.0.0.1]) (SolNet-Check, port 10024) with LMTP id hDq6s+fI-2PZ for ; Thu, 30 Apr 2009 19:56:55 +0000 (UTC) Received: from [192.168.1.4] (212-41-69-209.adsl.solnet.ch [212.41.69.209]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail01.solnet.ch (Postfix) with ESMTPSA id 88EC14B572 for ; Thu, 30 Apr 2009 19:56:55 +0000 (UTC) Message-Id: From: =?ISO-8859-1?Q?Marcel_St=F6r?= To: Tomcat Users List Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Reply-To: marcel@frightanic.com Subject: Static resources not found in embedded Tomcat Mime-Version: 1.0 (Apple Message framework v930.3) Date: Thu, 30 Apr 2009 21:56:53 +0200 X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org All I need for an embedded Tomcat (I'm working with 6.x) are a few =20 Tomcat JARs in my classpath, correct? I'm asking because I'm seeing a strange behavior here. Access to =20 Servlets deployed in the embedded Tomcat succeed, but requests to =20 other resources such as JSPs or static CSS files result in 404 errors. I have a feeling that I'm missing something in my Tomcat setup. Here's =20= my Tomcat launcher class: public class EmbeddedTomcat { private String context =3D null; private String docBase; private int port; private Embedded container =3D null; private Log logger =3D LogFactory.getLog(getClass()); /** * Creates a single-webapp configuration to be run in Tomcat. * * @param contextRoot without leading slash, e.g. "mywebapp" * @param docBase the web resources directory for the web application =20= i.e. the * absolute (or relative) path to the content to be served under =20 "mywebapp" * @param port the port */ public EmbeddedTomcat(String contextRoot, String docBase, int port) { assert !contextRoot.startsWith("/"); this.context =3D "/" + contextRoot; this.docBase =3D docBase; this.port =3D port; setupContainer(); } private void setupContainer() { // create server container =3D new Embedded(); container.setCatalinaHome(findTomcatHome()); // create webapp loader WebappLoader loader =3D new =20 WebappLoader(this.getClass().getClassLoader()); // create context Context rootContext =3D container.createContext(context, docBase); rootContext.setLoader(loader); rootContext.setReloadable(true); // create host Host localHost =3D container.createHost("localHost", new =20 File("").getAbsolutePath()); // one could call addChild for each web app... localHost.addChild(rootContext); // create engine Engine engine =3D container.createEngine(); engine.setName("localEngine"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); container.addEngine(engine); // create http connector Connector httpConnector =3D container.createConnector((InetAddress) =20= null, port, false); container.addConnector(httpConnector); container.setAwait(true); } /** * Tomcat will create its "work" directory in this folder! Hence, the =20= process * must have write access to it. To make this portable the system =20 property * java.io.tmpdir is suffixed with "embedded-tomcat". */ private String findTomcatHome() { String path; try { path =3D new File(System.getProperty("java.io.tmpdir"), "embedded-=20= tomcat").getCanonicalPath(); } catch (IOException e) { path =3D "embedded-tomcat"; } return path; } /** * Starts the embedded Tomcat server. * * @throws LifecycleException if the server could not be started */ public void start() throws LifecycleException { // starts server container.start(); // add shutdown hook to stop server Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { EmbeddedTomcat.this.stop(); } }); } /** * Stops the embedded Tomcat server. */ public void stop() { try { if (container !=3D null) { container.stop(); } } catch (LifecycleException exception) { logger.warn("Cannot Stop Tomcat" + exception.getMessage()); } } public String getContext() { return context; } public int getPort() { return port; } } That's how I start it: EmbeddedTomcat tomcat =3D new EmbeddedTomcat("myapp", "C:/=20 my_unpacked_war", 8888); tomcat.start(); C:/my_unpacked_war contains /WEB-INF/web.xml /WEB-INF/classes/... /css/style.css /index.jsp Requests to localhost:8888/myapp/index.jsp result in 404 and so does =20 localhost:8888/myapp/css/style.css. However if I access the Servlets =20 directly with the URLs they're mapped under everything works fine. Kind regards, Marcel --=20 Marcel St=F6r, http://www.frightanic.com Blog: http://frightanic.wordpress.com Couchsurfing: http://www.couchsurfing.com/people/marcelstoer Skype: marcelstoer --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org