简体   繁体   English

在代码存储库中同步Eclipse .classpath

[英]Synchronizing Eclipse .classpath in code repository

My team handles several Java projects using Eclipse, and shares the code using a code repository. 我的团队使用Eclipse处理多个Java项目,并使用代码存储库共享代码。

When a developer adds, removes or updates a jar file, the build is broken for everybody else, until they update their build path in Eclipse. 当开发人员添加,删除或更新jar文件时,构建将被其他所有人破坏,直到他们在Eclipse中更新其构建路径。 This process involves cumbersome email synchronization. 此过程涉及繁琐的电子邮件同步。

For several reasons, we have decided not to commit the .classpath file to the repo. 由于多种原因,我们决定不将.classpath文件提交到repo。 Instead, we came up with the following idea: Each project will have a committed file, say jars.list , which contains a list of jar files (and patterns). 相反,我们提出了以下想法:每个项目都有一个提交文件,比如说jars.list ,其中包含一个jar文件(和模式)列表。 A script will convert this file into a local .classpath for eclipse. 脚本会将此文件转换为eclipse的本地.classpath Whenever a developer changes its jars, it is his or her responsibility to change jars.list and commit it. 每当开发人员更换其jar时,更改jars.list并提交它是他或她的责任。

Is this a reasonable solution? 这是合理的解决方案吗? Are there any existing solutions for this problem? 这个问题有没有现成的解决方案?

Eclipse .project and .classpath files are intended/designed to be checked into a version control repository (cvs, svn, git, etc). Eclipse .project.classpath文件旨在/设计用于检入版本控制存储库(cvs,svn,git等)。 See this page in the Eclipse wiki. 请参阅Eclipse wiki中的此页面

There are various ways to keep the .classpath file "clean" (ie, free from absolute paths), which I mentioned in the Comments section above. 有各种方法可以保持.classpath文件“干净”(即,没有绝对路径),我在上面的评论部分提到过。

The build is broken because the absolute path to the JAR is different in each developer machine? 构建被破坏是因为每个开发人员机器中JAR的绝对路径是不同的? If so, you could add a user variable to avoid the issue, this way each developer only have to configure one variable (like LIB_DIR ): 如果是这样,您可以添加用户变量以避免此问题,这样每个开发人员只需配置一个变量(如LIB_DIR ):

<classpathentry kind="var" path="LIB_DIR/path/to/file.jar"/>

There are other solutions. 还有其他解决方案。 You could configure some user libraries in eclipse to group your JARs, and then export a .userlibraries file which could be shared in your repo. 您可以在eclipse中配置一些用户库以对JAR进行分组,然后导出可以在您的.userlibraries中共享的.userlibraries文件。 This way, there would be no absolute paths in .classpath , but they would be present in your .userlibraries . 这样, .classpath就没有绝对路径,但它们会出现在.userlibraries

You could also use some tool like Maven to manage dependencies on your project. 您还可以使用Maven之类的工具来管理项目的依赖项。

Anyway, I think you could share .classpath without problems... 无论如何,我认为你可以毫无问题地分享.classpath ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM