如何正确地对 Java 项目(Maven、Spring)进行版本控制(svn:ignore)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6304299/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:16:54  来源:igfitidea点击:

How to correctly version control (svn:ignore) a Java project (Maven, Spring)?

javasvnspringmavenignore

提问by Robert Niestroj

i was on a 2-day training introducing as to Java EE. We used there Java EE, Spring Framework, Maven, Springsource Tool Suite (Eclipse), Tomcat.

我参加了为期 2 天的 Java EE 介绍培训。我们使用了 Java EE、Spring Framework、Maven、Springsource Tool Suite (Eclipse)、Tomcat。

I took the Eclipse workspace we created there and run it on my work PC. I had, if i remember correctly, only to configure Tomcat properly, and it worked on my PC.

我使用了我们在那里创建的 Eclipse 工作区并在我的工作 PC 上运行它。如果我没记错的话,我只需要正确配置 Tomcat,它就可以在我的 PC 上运行。

Now i want to save the created Eclipse workspace containing 5 "sub"-projects in subversion so that my work colleagues can checkout this to them and run it on their computers.

现在我想在 subversion 中保存创建的包含 5 个“子”项目的 Eclipse 工作区,以便我的同事可以向他们签出并在他们的计算机上运行它。

How to do this correctly? I found somewhere a svn:ignore rule:

如何正确地做到这一点?我在某处找到了 svn:ignore 规则:

.classpath
.project
.settings
target

Using tortoiseSVN i added to the folder with the workspace this ignore rule, but the found out that the underlying folders target were'nt deleted so i deleted them manually and "added to ignore list". But after that the project in spring source tool suite does not see the mevan dependencies (i think so) because the imports are broken. STS underlines org. in the imports and says it can not resolve this.

使用 tortoiseSVN 我将这个忽略规则添加到带有工作区的文件夹中,但是发现底层文件夹目标没有被删除,所以我手动删除了它们并“添加到忽略列表”。但在那之后,spring 源工具套件中的项目没有看到 mevan 依赖项(我认为是这样),因为导入已损坏。STS 下划线 org。在进口中并说它无法解决这个问题。

How do i correctly version control such a project?

我如何正确地控制这样一个项目?

回答by Daniel Lundmark

In my project we are using Maven and Eclipse (Helios, currently) and the Maven plugins for Eclipse:

在我的项目中,我们使用 Maven 和 Eclipse(目前是 Helios)以及 Eclipse 的 Maven 插件:

Maven Integration for Eclipse Maven Integration for WTP

用于 Eclipse 的 Maven 集成 用于 WTP 的 Maven 集成

We only have the pom.xml file and the src/ directory tree in our version control system. We make sure notto add the eclipse files there. Then when a new developer starts in the project they do Import -> Maven -> Existing Maven Projects. The Maven plugins for Eclipse then set up perfect build paths, settings and so on.

我们的版本控制系统中只有 pom.xml 文件和 src/ 目录树。我们确保不要在那里添加 eclipse 文件。然后,当一个新的开发人员在项目中开始时,他们会执行 Import -> Maven -> Existing Maven Projects。Eclipse 的 Maven 插件然后设置完美的构建路径、设置等。

This way it is also very easy to re-import your projects into Eclipse as needed.

通过这种方式,根据需要将您的项目重新导入 Eclipse 也非常容易。

So, my tip is to leave the Eclipse files out of SVN and make sure you can setup the project correctly automatically simply by importing a Maven project.

因此,我的建议是将 Eclipse 文件排除在 SVN 之外,并确保您可以通过导入 Maven 项目来自动正确设置项目。

回答by Agemen

If I understand your problem the right way, you need to configure Eclipse in order to be able to launch tomcat from it. The key, here, is not maven anymore, but Eclipse, I think. As you've made modifications in your workspace that can't be put in your maven configuration file (the pom.xml), you become "Eclipse dependant".

如果我以正确的方式理解您的问题,您需要配置 Eclipse 以便能够从中启动 tomcat。我认为,这里的关键不再是 maven,而是 Eclipse。当您在工作区中进行了无法放入 maven 配置文件(pom.xml)的修改时,您将成为“依赖 Eclipse”。

The key here is that, as you're Eclipse dependant, you need the Eclipse configuration files to work. Consequently, I'm afraid you need to add back .classpath, .project, .settingsto your versioning tool... It's not generic, because you force people who work on your project to use Eclipse. But if everybody in your team do so, it shouldn't be a problem.

这里的关键是,由于您依赖 Eclipse,因此需要 Eclipse 配置文件才能工作。因此,恐怕你需要添加回.classpath.project.settings你的版本控制工具......这不是通用的,因为你强迫人们谁在你的项目的工作人员使用Eclipse。但是如果你团队中的每个人都这样做,那应该不是问题。

As I don't use Eclipse anymore, I don't know if versioning theses files can lead to problems. However, I hope this answer will help you to configure your project back...

由于我不再使用 Eclipse,我不知道对这些文件进行版本控制是否会导致问题。但是,我希望这个答案能帮助您重新配置您的项目......

EDIT : to be more accurate... and maybe give a better answer.

编辑:为了更准确......也许会给出更好的答案。

When using a version control system, the main goal is often (always ?) to give all the keys to use the sources, and develop from them. Consequently, you need to put in your VCS your sources, and all the configurations needed to use them efficiently.

使用版本控制系统时,主要目标通常是(总是?)提供使用源代码的所有密钥,并从中进行开发。因此,您需要将源代码以及有效使用它们所需的所有配置放入 VCS。

In your specific case, the key is that you've become Eclipse dependant through its Springsource Tool Suite plugin. Consequently, it becomes essential to add the configuration files for this tool, because they can't work without them, and if they can't work, you can't work.

在您的特定情况下,关键是您已经通过其 Springsource Tool Suite 插件依赖 Eclipse。因此,为这个工具添加配置文件变得至关重要,因为没有它们它们就无法工作,如果它们不能工作,你就无法工作。

回答by lepike

I can tell you my way of subversioning maven eclipse projects. First, when you create the project structure you have to committhe .setting, .classpath, .projectfiles into the subversion repository. If you can't do this the other colleagues will can not use the project structure after checkout. After you commit the project structure, the best way is not to commit these files except only when you change something important eclipse or build path settings, because the others will have conflicts due to the system dependent informations. Never commit the maven target directory. Sorry for my english. Hope it helps.

我可以告诉你我颠覆 Maven Eclipse 项目的方式。首先,当您创建项目结构时,您必须将.setting、.classpath、.project文件提交到 subversion 存储库中。如果您不能这样做,其他同事将无法在结帐后使用该项目结构。提交项目结构后,最好的方法是不要提交这些文件,除非您更改了一些重要的eclipse或构建路径设置,否则其他文件会因系统依赖信息而发生冲突。永远不要提交 Maven 目标目录。对不起我的英语不好。希望能帮助到你。