Return-Path: Delivered-To: apmail-felix-users-archive@minotaur.apache.org Received: (qmail 52779 invoked from network); 28 Dec 2010 23:14:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Dec 2010 23:14:51 -0000 Received: (qmail 73959 invoked by uid 500); 28 Dec 2010 23:14:50 -0000 Delivered-To: apmail-felix-users-archive@felix.apache.org Received: (qmail 73701 invoked by uid 500); 28 Dec 2010 23:14:50 -0000 Mailing-List: contact users-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@felix.apache.org Delivered-To: mailing list users@felix.apache.org Received: (qmail 73693 invoked by uid 99); 28 Dec 2010 23:14:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Dec 2010 23:14:50 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.212.49] (HELO mail-vw0-f49.google.com) (209.85.212.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Dec 2010 23:14:45 +0000 Received: by vws5 with SMTP id 5so3803469vws.22 for ; Tue, 28 Dec 2010 15:14:24 -0800 (PST) Received: by 10.220.46.3 with SMTP id h3mr628770vcf.113.1293578062463; Tue, 28 Dec 2010 15:14:22 -0800 (PST) Received: from arigato.home (pool-108-6-2-66.nycmny.fios.verizon.net [108.6.2.66]) by mx.google.com with ESMTPS id s9sm2775889vcr.46.2010.12.28.15.14.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Dec 2010 15:14:21 -0800 (PST) Message-Id: <2C2F36DC-F9BB-42CF-BAA1-D73F3904EB0F@xowave.com> From: Bjorn Roche To: users@felix.apache.org In-Reply-To: <4D1A5C7C.3030006@ungoverned.org> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: java.lang.NoClassDefFoundError: com/apple/eawt/ApplicationListener Date: Tue, 28 Dec 2010 18:14:20 -0500 References: <4D1A1D67.5010004@ungoverned.org> <4D1A5C7C.3030006@ungoverned.org> X-Mailer: Apple Mail (2.936) >>>> >>>> 3. The next step was to go through bit-by-bit and fix all the >>>> dynamic class loading and resource loading. Since I've actually >>>> not found good documentation explaining, from a user's >>>> standpoint, how to do this, I just centralized my code and found >>>> something that gets it done. If I'm doing it wrong, at least it's >>>> centralized so I can change it easily. >>>> >>>> - if a bundle is available (OSGi case) use the classloader from >>>> the bundle. >>>> - if there is an object that likely used the same classloader I >>>> wanted, which is often the case, get that object's classloader. >>>> - failing that, eg, if I'm in a static context -- I use something >>>> like this: >>>> Thread.currentThread().getContextClassLoader().loadClass(path); >>> >>> Not sure about all this. I have to assume you are doing some low- >>> level stuff, since bundles typically shouldn't be doing this sort >>> of thing. >> >> I'm not doing anything special or low-level that I'm aware of. I >> did that stuff because I discovered that >> Thread.currentThread().getContextClassLoader().getResource() >> doesn't work in OSGi, nor does the System Classloader, but using >> the bundle did work. >> >> What /should/ I be doing to dynamically load classes and resources? > > Typically, bundles shouldn't have to dynamically load classes > manually, so it sounds like an advanced use case so far. If you are > integrating legacy third-party stuff, then you might not have a > choice, but if it is your own stuff it can quite possibly be avoided > through the use of services. Hard to say. Okay. Theoretically, I could get rid of all the dynamic class loading, as it turns out to have been a bit overdesigned anyway, but leaving that asside, what about resources? If I just want a png or jpg from the classpath? That is pretty standard. For example, I load several thousand images from a resource directory, using code not unlike the code in the java tutorial (http://download.oracle.com/javase/tutorial/uiswing/components/icon.html ): /** Returns an ImageIcon, or null if the path was invalid. */ protected ImageIcon createImageIcon(String path, String description) { java.net.URL imgURL = getClass().getResource(path); if (imgURL != null) { return new ImageIcon(imgURL, description); } else { System.err.println("Couldn't find file: " + path); return null; } } "Low level" or not, can you clarify about the right way to do this? Is there a better way to do this than using the bundle? bjorn ----------------------------- Bjorn Roche http://www.xonami.com Audio Collaboration --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@felix.apache.org For additional commands, e-mail: users-help@felix.apache.org