[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
AW: AW: AW: [platform-core-dev] Getting the input stream for a resource - can't be that difficult!
|
Peter,
I managed to get the manifest.mf generated (it is not there by default) and after finding out that the classpath is a comma-separated list - it's now working.
Thanks a lot
Norbert
-----Ursprüngliche Nachricht-----
Von: Peter Kriens [mailto:Peter.Kriens@xxxxxxxx]
Gesendet: Donnerstag, 28. April 2005 12:31
An: Ploett Norbert
Betreff: Re: AW: AW: [platform-core-dev] Getting the input stream for a resource - can't be that difficult!
Ah, the nice little issues between OSGi and Eclipse. You should be
able to put this in the META-INF/MANIFEST.MF (this was generated by
Eclipse but is editable and Eclipse will read it).
Good luck :-)
Kind regards,
Peter Kriens
PN> Peter,
PN> thanks for your hint. After some search I have to admit that
PN> cannot find any "Bundle-Classpath manifest header" to put the dot
PN> in. Where do I find this?
PN> (Using eclipse 3.0.1)
PN> Norbert
PN> -----Ursprüngliche Nachricht-----
PN> Von: Peter Kriens [mailto:Peter.Kriens@xxxxxxxx]
PN> Gesendet: Donnerstag, 28. April 2005 09:18
PN> An: Ploett Norbert
PN> Betreff: Re: AW: [platform-core-dev] Getting the input stream
PN> for a resource - can't be that difficult!
PN> If you put the '.' in the Bundle-Classpath manifest header, then you
PN> can use your absolute version of the path name.
PN> An OSGi plugin has a single root, which is its JAR file. Eclipse, for
PN> some reason, puts the code in JAR files, but then uses a directory as
PN> the root, i.e. the plugin directory. This root is normally not
PN> searchable for classes. However, the OSGi has specified a
PN> Bundle-Classpath header that tells how to use the "root". The '.' is
PN> the root directory itself, but you can also specify directories or JAR
PN> files. These JARs/directories are then searched in order.
PN> You probably can achieve this by putting the plugin directory on the
PN> classpath (or any other directory you want searchable).
PN> Kind regards,
PN> Peter Kriens
PN>> Peter,
PN>> putting the resource into the class directory actually helps,
PN>> but it is not a practical option for me because I actually have
PN>> over a hundred files and the path is not fixed but computed on the
PN>> fly by my code. So I would like to have those hundred-something
PN>> files stowed neatly in an extra folder.
PN>> But thanks for your suggestion
PN>> Norbert
PN>> -----Ursprüngliche Nachricht-----
PN>> Von: Peter Kriens [mailto:Peter.Kriens@xxxxxxxx]
PN>> Gesendet: Mittwoch, 27. April 2005 15:56
PN>> An: Ploett Norbert
PN>> Cc: platform-core-dev@xxxxxxxxxxx
PN>> Betreff: Re: AW: [platform-core-dev] Getting the input stream
PN>> for a resource - can't be that difficult!
PN>> Hmm, this means that they move around files ... Can you put the
PN>> resource in the same directory as your class? Then
PN>> getClass().getResourceAsStream("myData.txt");
PN>> MUST work. It would be an error if that would not work. Eclipse is
PN>> mucking around a bit with the root. This should be OK in the near
PN>> future when they deliver their plugins as bundles (JAR files).
PN>> Kind regards,
PN>> Peter Kriens
PN>>> Peter,
PN>>> Tried it.
PN>>> Returns null :-(
PN>>> Norbert
PN>>> -----Ursprüngliche Nachricht-----
PN>>> Von: Peter Kriens [mailto:Peter.Kriens@xxxxxxxx]
PN>>> Gesendet: Mittwoch, 27. April 2005 15:25
PN>>> An: Ploett Norbert
PN>>> Cc: platform-core-dev@xxxxxxxxxxx
PN>>> Betreff: Re: [platform-core-dev] Getting the input stream for
PN>>> a resource - can't be that difficult!
PN>>> Try:
PN>>> InputStream in =
PN>>> getClass().getResourceAsStream("/data/myData.txt");
PN>>> That should work for any OSGi platform.
PN>>> Kind regards,
PN>>> Peter Kriens
PN>>>> Hello folks,
PN>>>> I need to read the content of a (text) file which is part of my plug-in.
PN>>>> I found a way to do this, but I feel I did it in a rather awkward
PN>>>> manner. Look at what I wrote:
PN>>>> =====snip=======
PN>>>> String path = "/data/myData.txt" ;
PN>>>> Bundle b = Platform.getBundle(PLUGIN_NAME);
PN>>>> URL url = Platform.find(b, new Path(path));
PN>>>> URL localUrl = null ;
PN>>>> InputStream is = null ;
PN>>>> InputStreamReader isr = null ;
PN>>>> try {
PN>>>> localUrl = Platform.resolve(url);
PN>>>> is = localUrl.openStream();
PN>>>> isr = new InputStreamReader(is);
PN>>>> } catch (IOException e) {
PN>>>> // TODO Auto-generated catch block
PN>>>> e.printStackTrace();
PN>>>> }
PN>>>> =====snap=======
PN>>>> The key seems to be to get an IFile for my URL, then the IFile will give
PN>>>> me the InputStream. But I could not figure out how to do this, hence the
PN>>>> hack (?) with Platform.resolve() and the localURL.
PN>>>> Or is this actually the way it must be done?
PN>>>> All hints appreciated.
PN>>>> Norbert
PN>>>> _______________________________________________
PN>>>> platform-core-dev mailing list
PN>>>> platform-core-dev@xxxxxxxxxxx
PN>>>> https://dev.eclipse.org/mailman/listinfo/platform-core-dev
--
Peter Kriens Mob +33633746480
9C, Avenue St. Drézéry Tel +33467542167
34160 Beaulieu, France Tel +15123514821
AOL,Yahoo pkriens ICQ 255570717