开发者

How to add source files of library jars?

I am using Eclipse IDE and its derivative like Spring IDE for Java development.

In a web application project, I add external jars like Spring MVC jars, Apache commons jars etc to the Web App library folder, hence they are automatically added to the build path. There are many jars in the Web App library folder.

I want to create folder in the project and add all the source files (zip/jar) of the libraries included in Web App library folder, so that I can navigate through the source of libraries from the Java editor window. Whenever I add a source zip/jar file to this folder, Eclipse should detect it and use it whenever I want to navigate to the source of a library.

Is the above possible in eclipse?

Note: I know how to add source files for each individual jar by navigating to the build path window and specifying the source location. But this i开发者_运维百科s very crude way, and I need to do for every library individually. Also the drawback is that source path is absolute, which means if I import the project into another computer then I need to create the source path or even worse I might have to add the source files individually again.


One way to automagically get the sources for the jars would be some kind of dependency management system. Most people would scream Maven (2/3) by now, but others exist and work well. Maven does have nice Eclipse integration, so that should be a plus.

The downside is that setting up a Maven project just for it's dependency management can seem overkill. Another point is that all the jars you depend on should be "Mavenized" as well.

As far as I know Eclipse wont automatically detect/scan source archive files and link them up to libraries in your workspace in the way you described it.


I agree with @Gressie on using Maven and the Eclipse Maven plugins -- as in that case it's just a matter of ticking a few boxes and Maven will do that for you. If however your project is not Maven-ized, you can still do this in Eclipse but it's more tedious:

  • for each one of the jars in your project (which appear under the dependecies section) right click on it and select properties
  • in the dialog that pops up you have (at least) 2 locations you can configure: java source attachment -- simply browse to your jar with the sources -- and also javadoc location (point it to the jar with javadoc if you want the javadoc to appear as a tooltip when you hover the mouse over one of the classes/methods/etc in that library).
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜