Java 有没有一种简单的方法可以在 Eclipse 中附加源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/122160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an easy way to attach source in Eclipse?
提问by Alex Argo
I'm a big fan of the way Visual Studio will give you the comment documentation / parameter names when completing code that you have written and ALSO code that you are referencing (various libraries/assemblies).
我非常喜欢 Visual Studio 在完成您编写的代码和您正在引用的代码(各种库/程序集)时为您提供注释文档/参数名称的方式。
Is there an easy way to get inline javadoc/parameter names in Eclipse when doing code complete or hovering over methods? Via plugin? Via some setting? It's extremely annoying to use a lot of libraries (as happens often in Java) and then have to go to the website or local javadoc location to lookup information when you have it in the source jars right there!
在完成代码或将鼠标悬停在方法上时,是否有一种简单的方法可以在 Eclipse 中获取内联 javadoc/参数名称?通过插件?通过一些设置?使用大量库(Java 中经常发生的情况),然后在源 jar 中找到信息时必须访问网站或本地 javadoc 位置以查找信息,这非常烦人!
回答by Henry B
Short answer would be yes.
简短的回答是肯定的。
You can attach source using the properties for a project.
您可以使用项目的属性附加源。
Go to Properties (for the Project) -> Java Build Path -> Libraries
转到属性(对于项目)-> Java 构建路径-> 库
Select the Library you want to attach source/javadoc for and then expand it, you'll see a list like so:
选择要为其附加源/javadoc 的库,然后展开它,您将看到如下列表:
Source Attachment: (none)
Javadoc location: (none)
Native library location: (none)
Access rules: (No restrictions)
Select Javadoc location and then click Edit on the right hahnd side. It should be quite straight forward from there.
选择 Javadoc 位置,然后单击右侧的编辑。从那里开始应该很简单。
Good luck :)
祝你好运 :)
回答by Matt
When you add a jar file to a classpath you can attach a source directory or zip or jar file to that jar. In the Java Build Path properties, on the Libraries tab, expand the entry for the jar and you'll see there's an item for the source attachment. Select this item and then click the Edit button. This lets you select the folder, jar or zip that contains the source.
当您将 jar 文件添加到类路径时,您可以将源目录或 zip 或 jar 文件附加到该 jar。在 Java Build Path 属性中,在 Libraries 选项卡上,展开 jar 条目,您将看到源附件有一个项目。选择此项,然后单击“编辑”按钮。这使您可以选择包含源的文件夹、jar 或 zip。
Additionally, if you select a class or a method in the jar and CTRL+CLICK on it (or press F3) then you'll go into the bytecode view which has an option to attach the source code.
此外,如果您在 jar 中选择一个类或一个方法并在其上按 CTRL+CLICK(或按 F3),那么您将进入字节码视图,该视图具有附加源代码的选项。
Doing these things will give you all the parameter names as well as full javadoc.
执行这些操作将为您提供所有参数名称以及完整的 javadoc。
If you don't have the source but do have the javadoc, you can attach the javadoc via the first method. It can even reference an external URL if you don't have it downloaded.
如果您没有源代码但有 javadoc,则可以通过第一种方法附加 javadoc。如果您没有下载它,它甚至可以引用外部 URL。
回答by Akrikos
Another thought for making that easier when using an automated build:
在使用自动构建时使这更容易的另一个想法:
When you create a jar of one of your projects, also create a source files jar:
project.jar
project-src.jar
当您创建一个项目的 jar 时,还要创建一个源文件 jar:
project.jar
project-src.jar
Instead of going into the build path options dialog to add a source reference to each jar, try the following: add one source reference through the dialog. Edit your .classpath and using the first jar entry as a template, add the source jar files to each of your other jars.
不要进入构建路径选项对话框为每个 jar 添加源引用,而是尝试以下操作:通过对话框添加一个源引用。编辑您的 .classpath 并使用第一个 jar 条目作为模板,将源 jar 文件添加到每个其他 jar 中。
This way you can use Eclipse's navigation aids to their fullest while still using something more standalone to build your projects.
通过这种方式,您可以最充分地使用 Eclipse 的导航辅助,同时仍然使用更独立的东西来构建您的项目。
回答by stolsvik
I've found that sometimes, you point to the directory you'd assume was correct, and then it still states that it can't find the file in the attached source blah blah.
我发现有时,您指向您认为正确的目录,然后它仍然指出它无法在附加的源代码中找到该文件等等。
These times, I've realized that the last path element was "src". Just removing this path element (thus indeed pointing one level above the actual path where the "org" or "com" folder is located) magically makes it work.
这些时候,我意识到最后一个路径元素是“src”。只需删除此路径元素(因此确实指向“org”或“com”文件夹所在的实际路径上方一层)就可以神奇地使其工作。
Somehow, Eclipse seems to imply this "src" path element if present, and if you then have it included in the source path, Eclipse chokes. Or something like that.
不知何故,Eclipse 似乎暗示了这个“src”路径元素(如果存在),并且如果您将它包含在源路径中,Eclipse 就会窒息。或类似的东西。
回答by Nilesh Tailor
Another option is to right click on your jar file which would be under (Your Project)->Referenced Libraries->(your jar) and click on properties. Then click on Java Source Attachment. And then in location path put in the location for your source jar file.
另一种选择是右键单击位于 (Your Project)->Referenced Libraries->(your jar) 下的 jar 文件,然后单击属性。然后单击 Java 源附件。然后在位置路径中放入源 jar 文件的位置。
This is just another approach to attaching your source file.
这只是附加源文件的另一种方法。
回答by nevets1219
I was going to ask for an alternative to attaching sources to the same JAR being used across multiple projects. Originally, I had thought that the only alternative is to re-build the JAR with the source included but looking at the "user library" feature, you don't have to build the JAR with the source.
我打算寻求一种替代方法来将源附加到跨多个项目使用的同一个 JAR。最初,我认为唯一的选择是重新构建包含源代码的 JAR,但查看“用户库”功能,您不必使用源代码构建 JAR。
This is an alternative when you have multiple projects (related or not) that reference the same JAR. Create an "user library" for each JAR and attach the source to them. Next time you need a specific JAR, instead of using "Add JARs..." or "Add External JARs..." you add the "user library" that you have previously created.
当您有多个项目(相关或不相关)引用同一个 JAR 时,这是一种替代方法。为每个 JAR 创建一个“用户库”并将源附加到它们。下次您需要特定 JAR 时,不要使用“添加 JAR...”或“添加外部 JAR...”,而是添加您之前创建的“用户库”。
You would only have to attach the source ONCE per JAR and can re-use it for any number of projects.
您只需为每个 JAR 附加一次源代码,并且可以将其重用于任意数量的项目。
回答by Alex Argo
It may seem like overkill, but if you use maven and include source, the mvn eclipse plugin will generate all the source configuration needed to give you all the in-line documentation you could ask for.
这似乎有点矫枉过正,但如果您使用 maven 并包含源代码,mvn eclipse 插件将生成所需的所有源代码配置,以提供您可能需要的所有内嵌文档。
回答by Muzikant
Another way is to add the folder to your source lookup path: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdebug%2Fref-editsourcelookup.htm
另一种方法是将文件夹添加到您的源查找路径:http: //help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdebug%2Fref-编辑源查找.htm
回答by Ambika
yes there is a easy way... go to ... http://sourceforge.net/projects/jdk7src/and download the zip file. Then attach this to the eclipse. Give the path where you have downloaded the zip file in eclipse. We can then browse through the source.
是的,有一个简单的方法...去... http://sourceforge.net/projects/jdk7src/并下载 zip 文件。然后将其附加到日食。给出你在eclipse中下载zip文件的路径。然后我们可以浏览源代码。
回答by tterrace
Up until yesterday I was stuck painstakingly downloading source zips for tons of jars and attaching them manually for every project. Then a colleague turned me on to The Java Source Attacher. It does what eclipse should do - a right click context menu that says "Attach Java Source".
直到昨天,我一直在煞费苦心地下载大量 jar 的源 zip,并为每个项目手动附加它们。然后一位同事让我转而使用The Java Source Attacher。它执行 eclipse 应该做的事情 - 一个右键单击上下文菜单,上面写着“附加 Java 源代码”。
It automatically downloads the source for you and attaches it. I've only hit a couple libraries it doesn't know about and when that happens it lets you contribute the url back to the community so no one else will have a problem with that library.
它会自动为您下载源代码并附加它。我只访问了几个它不知道的库,当发生这种情况时,它可以让您将 url 贡献回社区,这样其他人就不会对该库有问题。