Reputation: 6086
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
Reputation: 5291
Ways to guess whether there's a package present in the JVM in runtime:
java.version
)javax.xml.soap
using reflectionIn 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
Reputation: 4338
If you wan't to find out if a class is included in the JRE you have, do the following:
rt.jar
of your JRE, mine was at /usr/lib/jvm/jdk1.7.0_07/jre/lib/rt.jar
.zip
viewerIf you wan't to find out if the JRE you're running at contains your class, do the following:
Class.forName
with the classname of the class you wan't to testClassNotFoundException
, its not there!Upvotes: 1
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