How can I link source to a jar package in eclipse?

こ雲淡風輕ζ 提交于 2019-12-17 19:15:03

问题


How can I link source to a jar package in eclipse?

I am trying to add the external library ch.ntb.usb.

I added the jar file to my build path, but when I tried to run the application it returned the following error:

The jar file ch.ntb.usb has no source attachment.

I've used JD-GUI to decompile the jar file and the source code is contained.


回答1:


I doubt that you get that error when you only run the project unless you have an error in your code and eclipse debugger try to show the line of code that cause the exception, anyway you may need source files of a library for debugging purpose, to link source to a jar package in eclipse you can follow these simple steps :

  • Find the package which you want to add the source under Referenced Libraries in Package Explorer
  • Right Click on the library
  • Select Properties
  • Go under Java Source Attachment
  • Select the directory or archive where your source is located.




回答2:


I "Saved all sources" with jd-gui into my build path as ch.ntb.usb.src after unzipping the jar file. Then I set the source attachment of the external library to ch.ntb.usb.src. This fixed the issue.




回答3:


I Know it is pretty late but it will be helpful for the other user, as we can do Job using three ways... as below
1)1. Atttach your source code using
i.e, Right click on the project then properties --> Java build path--> attach your source in the source tab or you can remove jar file and attach the source in the libraries tab
2. Using eclipse source Analyzer
In the eclipse market you can download the plugin java source analyzer which is used to attach the open source jar file's source code. we can achieve it after installing the plugin, by right click on the open source jar and select the attach source option.
3. Using Jadclipse in eclipse you can do it
last not the least, you can achieve the decompile your code using this plugin. it is similar way you can download the plugin from the eclipse market place and install in your eclipse. in jadclipse view you can see your .class file to decomplile source format note here you cannot see the comment and hidden things




回答4:


  1. Click right in Package Explorer your Project
  2. Select Properties
  3. Select Android
  4. Scroll down
  5. Under Library click Add
  6. Select the needed Lib and press OK


来源:https://stackoverflow.com/questions/8454590/how-can-i-link-source-to-a-jar-package-in-eclipse

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