lviggiani
lviggiani

Reputation: 6086

Where to check whether a package is shipped with the JRE for Java

I'm using javax.xml.soap package in my java desktop application and I would like to check whether that package (and more in general any package shipped with JDK) is available in JRE's on different platforms (win, mac, linux) for deployment. The aim is to make sure that my application will run on target machines with JRE or check if full JDK is required. Also for linux I would like to make sure that the open-jdk jre 1.6 (not the oracle one) will be enough. Thanks

Upvotes: 1

Views: 669

Answers (3)

david a.
david a.

Reputation: 5291

Ways to guess whether there's a package present in the JVM in runtime:

  • Check the JRE version system property (java.version)
  • Try to load the classes you're expecting in javax.xml.soap using reflection

In practice, I'd however rather demand certain JRE(s) to be used to run my application in my system requirements, rather than just trying to detect whether a package is available.

Upvotes: 0

tilpner
tilpner

Reputation: 4338

If you wan't to find out if a class is included in the JRE you have, do the following:

  • Locate the rt.jar of your JRE, mine was at /usr/lib/jvm/jdk1.7.0_07/jre/lib/rt.jar
  • Open it with your favorite .zip viewer
  • Search for the wanted classes
  • You're done!

If you wan't to find out if the JRE you're running at contains your class, do the following:

  • Call Class.forName with the classname of the class you wan't to test
  • Put this in a try-catch-block
  • If you catch a ClassNotFoundException, its not there!
  • Note that this does not state if it is in the default library, just that is is on the classpath!

Upvotes: 1

gyorgyabraham
gyorgyabraham

Reputation: 2608

This effort on portability is very good! I would suggest you requiring Java 7 because OpenJDK7 is the default implementation for it, so no more "oracle java is better than openjdk". I think requiring Java 7 is better than requiring a specific Java implementation (Oracle) or "checking if it runs on openjdk 6". Anyways I'd suggest david's points!

Upvotes: 0

Related Questions