You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Bart Elen <Ba...@cs.kuleuven.be> on 2007/09/12 17:43:09 UTC
How to check if an optional package is available?
Hello,
When a package is imported with 'resolution:=optional', we have to check if the package is available
or not before we use it. But how do we do this?
Someone has experience with this problem?
Thanks,
Bart
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: How to check if an optional package is available?
Posted by Bart Elen <Ba...@cs.kuleuven.be>.
Thanks for the help Richard!
This solution works.
Greetings,
Bart
Richard S. Hall wrote:
> Bart Elen wrote:
>> Hello,
>>
>>
>> When a package is imported with 'resolution:=optional', we have to
>> check if the package is available or not before we use it. But how do
>> we do this?
>>
>> Someone has experience with this problem?
>
> Just try to load a class from that package and catch any exceptions...if
> you load the class successfully, then the package is available, if not
> then don't try to load any more, e.g.:
>
> boolean fooAvailable = false;
> try {
> this.getClass().getClassLoader().loadClass("org.foo.MyClass");
> fooAvailable = true;
> } catch (Exception ex) {
> // foo is not available.
> }
>
> Something like that.
>
> -> richard
>
>>
>>
>>
>> Thanks,
>>
>> Bart
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: How to check if an optional package is available?
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Bart Elen wrote:
> Hello,
>
>
> When a package is imported with 'resolution:=optional', we have to
> check if the package is available or not before we use it. But how do
> we do this?
>
> Someone has experience with this problem?
Just try to load a class from that package and catch any exceptions...if
you load the class successfully, then the package is available, if not
then don't try to load any more, e.g.:
boolean fooAvailable = false;
try {
this.getClass().getClassLoader().loadClass("org.foo.MyClass");
fooAvailable = true;
} catch (Exception ex) {
// foo is not available.
}
Something like that.
-> richard
>
>
>
> Thanks,
>
> Bart
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org