Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D9860200B76 for ; Tue, 30 Aug 2016 09:03:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D7D26160ABA; Tue, 30 Aug 2016 07:03:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2A5EC160AA8 for ; Tue, 30 Aug 2016 09:03:07 +0200 (CEST) Received: (qmail 46393 invoked by uid 500); 30 Aug 2016 07:03:05 -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 46382 invoked by uid 99); 30 Aug 2016 07:03:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Aug 2016 07:03:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 545781A0373 for ; Tue, 30 Aug 2016 07:03:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.554 X-Spam-Level: * X-Spam-Status: No, score=1.554 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id i8DXCRzKCAvi for ; Tue, 30 Aug 2016 07:03:01 +0000 (UTC) Received: from iron2.lex-com.net (smtp5.lex-com.net [193.159.191.10]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 6BCC95FAC6 for ; Tue, 30 Aug 2016 07:03:01 +0000 (UTC) X-IronPort-AV: E=Sophos;i="4.87,1,1363129200"; d="scan'208";a="58736212" Received: from unknown (HELO mucle03.lex-com.net) ([10.89.20.108]) by iron2.lex-com.net with ESMTP; 30 Aug 2016 09:02:53 +0200 In-Reply-To: References: To: "Tomcat Users List" MIME-Version: 1.0 Subject: Re: Housing and reading internal resources using Tomcat 8.5.4 and JDK 1.8 X-KeepSent: 24911870:D0471B50-C125801F:00263C35; type=4; name=$KeepSent X-Mailer: Lotus Notes Release 8.5.3 September 15, 2011 Message-ID: From: Christoph Nenning Date: Tue, 30 Aug 2016 09:02:50 +0200 X-MIMETrack: Serialize by Router on MUCLE03/Lexcom_Muenchen/LEXCOM(Release 9.0.1FP6|April 20, 2016) at 30.08.2016 09:03:01, Serialize complete at 30.08.2016 09:03:01 Content-Type: multipart/alternative; boundary="=_alternative 0026B717C125801F_=" archived-at: Tue, 30 Aug 2016 07:03:08 -0000 --=_alternative 0026B717C125801F_= Content-Type: text/plain; charset="US-ASCII" > Hello everyone, > > I have a file xyz.txt that is specific to my web application which needs to > be located by my web application, and I wish to find that resource via > getClass().ClassLoader().getResource("xyz.txt") at runtime. The xyz.txt > file has no relation to any particular Java class in our application. This > resource is used internally by the application and should not be served > directly by the container to inbound HTTP requests, therefore I have it > located in the WEB-INF/properties directory of my web app deployment. > However, the getResource("xyz.txt") method returns null, even though my > xyz.txt file is certainly where it is expected to be found. > > Where should I place this file ideally, and given that file exists in that > location, what is the parameter value I need to pass to getResource() so it > returns a non-null value? > > Thanks, Doug Hi, the file must be present in classpath. For a webapp that means WEB-INF/classes. When you place it not in a sub dir you must pass "/xyz.txt" to getResource() (note the leading slash). If you use eclipse for development you can create a "source folder" and place it there. eclipse will take care of copying it to WEB-INF/classes. Other IDEs or build tools call that a resources dir. In maven it defaults to src/main/resources. Regards, Christoph This Email was scanned by Sophos Anti Virus --=_alternative 0026B717C125801F_=--