Eclipse:通过本地属性将源代码/javadoc 附加到库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/300328/
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
Eclipse: Attach source/javadoc to a library via a local property
提问by Chris Conway
I have a third-party library in my SVN repository and I'd like to associate source/javadoc with it locally in Eclipse. I.e., there should be some local setting (for example, an entry in the local.properties
file) that associates the source/javadoc with the JAR file, but which doesn't introduce local dependencies into the repository via .classpath
. Ideally I'd have
我的 SVN 存储库中有一个第三方库,我想在 Eclipse 中将 source/javadoc 与其本地关联。即,应该有一些本地设置(例如,local.properties
文件中的一个条目)将源/javadoc 与 JAR 文件相关联,但不会通过.classpath
. 理想情况下我有
lib_src_dir = /my/path/to/lib/src
in local.properties
and then
在local.properties
然后
<classpathentry kind="lib" path="lib.jar" sourcepath="${lib_src_dir}">
in .classpath
. Can this be done?
在.classpath
。这能做到吗?
[EDIT] @VonC's answer is helpful... Is there a way to load Path Variables from a text file (e.g., local.properties
) instead of going through Window -> Preferences -> General -> Workspace -> Linked Resources?
[编辑] @VonC 的回答很有帮助......有没有办法从文本文件(例如,local.properties
)加载路径变量而不是通过窗口 -> 首选项 -> 常规 -> 工作区 -> 链接资源?
采纳答案by VonC
I believe this would be better achieved through:
我相信这可以通过以下方式更好地实现:
- the creation of a linked folder combined with
- the declaration of a linked resource
- 创建链接文件夹结合
- 链接资源的声明
The linked resource defines a path variable which would be equals to /my/path/to/lib/src
链接的资源定义了一个路径变量,它等于 /my/path/to/lib/src
The linked folder would refers to your linked resource
链接的文件夹将引用您的链接资源
(you can use a variable and not a fixed path, with the "Variable" button)
(您可以使用变量而不是固定路径,使用“变量”按钮)
The variable is actually always local (to one's workspace), and will be modified through the Linked Resources
preference screen.
该变量实际上始终是本地的(对于一个人的工作区),并且将通过Linked Resources
首选项屏幕进行修改。
The linked folder can also be... a linked file, thus allowing the reference of an archive through a relative path (relative to the variable).
Then this linked file (here a linked archive) can be associated to your classpathentry
in the "source
" attribute.
链接文件夹也可以是...链接文件,从而允许通过相对路径(相对于变量)引用存档。
然后这个链接的文件(这里是一个链接的存档)可以classpathentry
在“ source
”属性中关联到你的。
The problem with Linked Resources is they are local to the workspace, in the preferences.
You can export the preferences in a [myPrefs.epf]
file, and then trim the exported file in order to leave only the lines containing pathvariable
:
链接资源的问题在于它们在首选项中位于工作区的本地。
您可以导出[myPrefs.epf]
文件中的首选项,然后修剪导出的文件以仅保留包含pathvariable
以下内容的行:
/instance/org.eclipse.core.resources/pathvariable.MY_DIRECTORY=/my/path/to/lib/src
Anyone can then import this special preference file, which will only affect the "Linked Resources
" part.
然后任何人都可以导入这个特殊的首选项文件,它只会影响“ Linked Resources
”部分。
That solution is not very satisfying, since the .epf
preference file can not be loaded automatically in the project.
When I setup a project with a linked resources defining a path, I always leave a big README.txt
at the root of my project, in order to incite the user of said project to define that same linked resources with his/her own fixed local path.
该解决方案不是很令人满意,因为.epf
无法在项目中自动加载首选项文件。
当我设置一个带有定义路径的链接资源的项目时,我总是README.txt
在我的项目的根目录留下一个 big ,以鼓励该项目的用户使用他/她自己的固定本地路径定义相同的链接资源。
Several bugsare in progress to enhance this situation or around the Linked Resources topic.
Especially:
尤其:
- Exporting a project with linked resources
- Relative paths without variables
- Have linked resources relative to workspace paths
- Would like to use path relative to workspace root
DevByStarlightmentions in the commentsthe project (not very active since Oct. 2011) workspacemechanic.
DevByStarlight在评论中提到了该项目(自 2011 年 10 月以来不是很活跃)workspacemechanic。
The Workspace Mechanic automates maintenance of your Eclipse environment by tweaking preferences, adding extension locations, and so on. You can use it to:
- Create a consistent environment among groups as large as the entire company, your local team, or even among your own many workspaces
- Save time setting up new workspaces
- Create tasks that ensure your favorite new preferences are applied to all your current and future workspaces. (This is one of our favorite features!)
The key to the Workspace Mechanic's behavior is the
Task
.
A task describes a simple test and an action that, when run, changes the environment so the test will subsequently pass.Tasks
can come in many forms: preference files, Java classes, Groovy scripts and Eclipse extensions. You can easily define your own Tasks.
Workspace Mechanic 通过调整首选项、添加扩展位置等自动维护 Eclipse 环境。您可以将其用于:
- 在整个公司、您的本地团队甚至您自己的许多工作区之间创建一致的环境
- 节省设置新工作区的时间
- 创建任务以确保您最喜欢的新首选项应用于您当前和未来的所有工作区。(这是我们最喜欢的功能之一!)
工作区机械师行为的关键是
Task
.
任务描述了一个简单的测试和一个操作,当运行时,该操作会改变环境,因此测试随后将通过。Tasks
可以有多种形式:首选项文件、Java 类、Groovy 脚本和 Eclipse 扩展。您可以轻松定义自己的任务。
It comes with a collection of scripts:
它带有一组脚本:
回答by erickson
You can do this with classpath variables.
您可以使用类路径变量来做到这一点。
Each developer creates a couple of new variables at Window -> Preferences -> Java -> Build Path -> Classpath Variables.
每个开发人员在 Window -> Preferences -> Java -> Build Path -> Classpath Variables 处创建几个新变量。
Define a variable (say, JAVA_LIB_DIR) that points to a directory containing the third-party JAR (or JARS). Define another variable that points to a directory containing the third-party source code (JAVA_SRC_DIR). You can set this up how you like, but we have a structure like this:
定义指向包含第三方 JAR(或 JARS)的目录的变量(例如 JAVA_LIB_DIR)。定义另一个指向包含第三方源代码 (JAVA_SRC_DIR) 的目录的变量。您可以按照自己的喜好进行设置,但我们有这样的结构:
common/
lib/
java/ <-- JAVA_LIB_DIR variable points to this directory
axis/
bitronix/
1.0/bitronix.jar "extension" is "bitronix/1.0/bitronix.jar"
...
In your project's build path, use the "Add Variable..." option to add the library. Then you when "attach source," you'll be prompted for a variable and extension to the source code.
在项目的构建路径中,使用“添加变量...”选项添加库。然后,当您“附加源代码”时,系统会提示您输入源代码的变量和扩展名。
This way, a single, shared .classpath file can be checked-in, while allowing each developer to locate their own library and source directories where they like.
这样,可以签入单个共享的 .classpath 文件,同时允许每个开发人员在他们喜欢的地方找到自己的库和源目录。
回答by alphonzo79
I just figured out a simple answer to this (in Indigo) after working on it in the background and free moments for a couple of days. The easiest way I've found is to expand your project in the Project Explorer, go into your Referenced Libraries, right-click the appropriate referenced JAR and click Properties. In there you have the options to designate a JavaDocs location. Enter the location of the folder that contains index.html and packages-list, files that are part of the Javadocs. Piece of cake!
我只是想出了一个简单的答案(在 Indigo 中)在后台和几天的空闲时间工作之后。我发现的最简单的方法是在项目资源管理器中展开您的项目,进入您的引用库,右键单击适当的引用 JAR,然后单击属性。在那里,您可以选择指定 JavaDocs 位置。输入包含 index.html 和 packages-list 的文件夹的位置,这些文件是 Javadoc 的一部分。小菜一碟!
The only problem I see so far is that I bet you need to do this in every projects that references that library.
到目前为止,我看到的唯一问题是,我敢打赌,您需要在引用该库的每个项目中都这样做。