checking whether a package is existent or not

前端 未结 3 1734
逝去的感伤
逝去的感伤 2020-12-17 17:46

How can i check whether a package like javax.servlet.* exists or not in my installation of java?

3条回答
  •  无人及你
    2020-12-17 18:28

    Check if package is present as a resource:

    // Null means the package is absent
    getClass().getClassLoader().getResource("javax/servlet");
    

    Alternatively, check if some class of this package can be loaded via Class.forName(...).

提交回复
热议问题