I recently met very strange behavior of the getResourceAsStream method.
I have an application that I developed on Windows. This application is an OSGI-based desktop application. I created the package, installed the necessary packages, and added some data files to these packages so that they are contained in the jar file.
I am loading data using this:
this.getClass().getResourceAsStream("pl/com/myapp/resource.dat");
It worked great both in eclipse and when I deployed my application and ran it on a system outside of the IDE.
Then I transferred the development to ubuntu 12.04. To my surprise, the method mentioned above always returns null. Data is where it should be. All settings look OK. There are no absolute paths in any configuration files.
I have tried many different things. I changed the path to:
this.getClass().getResourceAsStream("/pl/com/myapp/resource.dat");
I tried not to contain the package root, but insert the path related to the location of the class (let's say my class is: pl.com.myapp.MyClass):
this.getClass().getResourceAsStream("resource.dat");
I also tried:
this.getClass().getResourceAsStream("./resource.dat");
But nothing happened: (
But when I create a simple Java application, everything works smoothly, and the method returns the correct thread.
Has anyone encountered such problems?
I am using eclipse-juno on ubuntu 12.04.
Marcin roguski
source share