开发者

How to examine required libraries?

I developing a web application with a lot of libraries like, Spring, Apach开发者_开发技巧e CXF, Hibernate, Apache Axis, Apache Common and so one. Each of these framework comes with a lot of *.jar libraries.

For development I simple take all of the delivered libraries and add them to my classpath.

For deployment not all of these libraries are required, so is there a quick way to examine all the required libraries (*.jar) which are used by my source code?


If you move your project to use Maven such things become easier:

mvn dependency:analyze 
mvn dependency:tree


For your example, Maven + IDE + nice dependency diagrams could help allot.

See an example of this : it's much easier this way to figure out what happens in a project, and this way you don't need to add to your project "all delivered libraries" - just what it's required.


JDepend traverses Java class file directories and generates design quality metrics for each Java package. JDepend allows you to automatically measure the quality of a design in terms of its extensibility, reusability, and maintainability to manage package dependencies effectively.


So, as a quick, dirty, and potentially inefficient way, you can try this in Eclipse:

  1. Create two copies of your project.
  2. In project copy #2 remove all the jars from the classpath.
  3. Pick a source file that now has errors because it can't resolve a class reference. Pick one of the unresolved classes and note its fully qualified class name.
  4. Do Control-Shift-T and locate the unresolved class. You should be able to see which jar its contained in since all the jars are still in the classpath for project copy #1.
  5. Add the jar that contains this unresolved class back into your classpath in project copy #2, then repeat steps 3 and 4 until all class references are resolved.

Unfortunately you're not done yet since the jar files themselves may also have dependencies. Two ways to deal with this:

  1. Go read the documentation for all the third-party packages you're using. Each package should tell you what its dependencies are.

  2. Run your application and see if you get any ClassNotFoundExceptions. If you do, then use Control-Shift-T to figure out what jar that class comes from and add it to your classpath. Repeat until your project runs without throwing any ClassNotFoundExceptions.

The problem with #2 is that you don't really know you've resolved all the dependencies since you can't simulate every possible execution path your project might take.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜