Check if jar file is loaded?

帅比萌擦擦* 提交于 2019-12-22 08:44:58

问题


I have a custom jar file in the tomcat lib/ folder. As per my knowledge, any jar file in this folder will be loaded on startup.

Is there anyway I can check if a particular jar file is loaded or not?

I'm running tomcat-6.0.35.A on unix rhel5.


回答1:


I think I have seen which jars are open on startup in one of Tomcat log files. If not I could think about two possible alternatives:

  1. Add -verbose:class to JAVA_OPTS in Tomcat startup script. It should print classes as they're loaded by JVM (lots of output). Grep log file (or stdout) to find if classes from your jar are listed
  2. Use Linux lsof command to see files opened by the Tomcat process.



回答2:


Jars aren't really "loaded on startup". But Tomcat's system class loader is loading classes from those jars. You can check if some class from the jar is available either:

  • by trying to load that class from your code, e.g. getClass().getClassloader().loadClass(className)
  • by trying to load class as a resource, e.g. getClass().getResource("/" + className.replace('.', '/') + ".class")

In second case you should have name or your jar file in the url returned by getResource().



来源:https://stackoverflow.com/questions/9909334/check-if-jar-file-is-loaded

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!