• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How can you check for the existance of system packages?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to be able to check whether certain system packages exist when my Java app loads. For my specific use-case the system packages are listed in a .properties file. I assumed that I could use for example ClassLoader.getSystemResource("javax/swing"); to test whether a specific package exists, but this doesn't work. However the following works for other packages on my classpath: myClassLoader.getResource("com/example/mypackage");

This is a simple runnable example:

The console output you will see when you run this program is:
Found [com/example/mypackage] with myClassLoader
Could not find [javax/swing]

Is there any way to check for system packages without having to know the classes they contain?

For the curious, my application is embedding the Felix OSGi runtime into a webapp. The system classes which my OSGi bundles need are specified in a .properties file and I would like to be able to check that all the packages exist before I boot OSGi. Without the check, the only way I know if a system package doesn't exist (for example, I miss spelt it in the .properties file) is when an OSGi bundle that needs it tries to load a class and gets a NoClassDefFoundError.

Thanks in advance for your help.
Steve Bentley
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out java.lang.Package
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic