Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Accessing files of a feature project during runtime



On Fri, Apr 20, 2018 at 10:43 AM, Simon Scholz <simon.scholz@xxxxxxxxxxx> wrote:
Hi guys,

is there a way to access files from features?

With bundles it works pretty straight forward:

Bundle bundle = Platform.getBundle("myBundlesSymbolicName");

It's not good to do this... what if you have multiple versions of the same bundle? It's also an unnecessary Eclipsism.

 
or

Bundle bundle = FrameworkUtil.getBundle(getClass());

A little better, but calling this.getClass() has bitten people in the past. What if somebody sub-classes your class in another bundle? "This" will not be the "this" that you think it is and you might get a completely unexpected bundle object.

It is far, far, FAR better to get your bundle simply by being a Declarative Services component, as follows:

@Component
public class MyComponent {
@Activate
void activate(BundleContext context) {
Bundle myBundle = context.getBundle();
// This is MY bundle and nobody can take it away from me!
}
}

 

and then using the FileLocator to get resources inside the bundle.

Nope... I don't know what FileLocator is, probably another unnecessary Eclipsism! Once you have the bundle you can just call Bundle.getResource().
 

Unfortunately there is nothing like:

Feature feature = Platform.getFeature("myFeatureId"); + a way to get
files from this feature JAR.

Can someone tell me how to do that in the right way?

See Mark Hoffmann's answer. As he said, features don't exist at runtime, they are just lists of bundles.

Regards,
Neil
 

Thanks in Advance,

Simon Scholz


--
--
Trainer, Consultant and Developer

vogella GmbH
Haindaalwisch 17a, 22395 Hamburg
Amtsgericht Hamburg: HRB 127058
Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
USt-IdNr.: DE284122352
Tel (040) 78804360, Fax (032) 221739404, Email:
simon.scholz@xxxxxxxxxxx, Web: http://www.vogella.com
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/equinox-dev


Back to the top