Reputation: 8385
I 've developed an eclipse plugin and in that I have a java file trying to read directories and then populate result accordingly. When I try to run the file from eclipse itself through Run>Java application , it gives me proper result but as soon as I try to run the same through Eclipse Application, it is throwing NullPointerException because unable to find the directory.
I tried the following ways- Suppose , I have a package as -
Package - com.test.abhishek.file.java.TestWork.java
Directories - com.test.abhishek.file.java.Dir1 com.test.abhishek.file.java.Dir2 Now in TestWork.java- InputStream is = HelpContentView.class.getResourceAsStream("/"+dirName);**
The above line is getting failed. How should I keep my directory and where so that it will run as an eclipse plug-in as well.
Tried to find the class path by TestWork.class.getClassLoader().getResource("").getPath() and getting the output as / So now where should I dump my directories to ressolve.
Upvotes: 2
Views: 1558
Reputation: 29547
It looks like you need the findEntries API.
For some example code, check out the related question (and answer) at How to test if a URL from an Eclipse bundle is a directory?
Upvotes: 1
Reputation: 13628
Just trying to understand what you are doing. You have a directory within your source structure that you want to get? Eclipse plugins are normally placed in the /plugins directory jar'ed up. This means you either A) need to bundle your resources with your plugin using build.properties, or put them somewhere else in the file structure and access it using normal File IO mechanisms.
If you are creating a plugin you most likely want to use Bundle.getEntry instead
public void start(BundleContext context) {
Bundle bundle = context.getBundle();
InputStream in = bundle.getEntry("/"+dirName").openStream();
}
Upvotes: 2