简体   繁体   English

Java版本控制

[英]Java version control

I am using docx4j to load, manipulate and save Word files. 我正在使用docx4j加载,操作和保存Word文件。 Everything works perfectly but there is one thing i don't know how to implement it. 一切正常,但有一件事我不知道如何实现。 What I want is something like a version control - that means if you save a document it shall be possible to recover a earlier version of this document (eg by saving only the delta). 我想要的是类似版本控制的内容-这意味着,如果保存文档,则可以恢复该文档的较早版本(例如,仅保存增量)。 Maybe you can describe it that is should be something like SVN or Git where you can go back to an earlier version of your files. 也许您可以形容它应该是SVN或Git之类的东西,您可以在其中返回到早期版本的文件。 The problem is that i do not know any possibility to realize that. 问题是我不知道有任何可能实现这一点。 So I hope that anyone of you can help me. 所以我希望你们中的任何人都可以帮助我。 It would be fine if anyone at least know a package or something else that can do this with files in general and not especially with the docx Files. 如果任何人至少知道一个软件包或其他可以对文件进行此操作的东西,而不是对docx文件,尤其如此,那将是很好的。 Thanks for your help! 谢谢你的帮助!

Edit: I am sorry that my question was imprecise. 编辑:对不起,我的问题是不准确的。 This was my first post here, in future i will improve ;) 这是我在这里的第一篇文章,以后我会改进;)

JGit is a Java implementation of Git that will work with few dependencies. JGit是Git的Java实现,几乎没有依赖项。 Similar libraries exist for SVN and CVS. SVN和CVS存在类似的库。 Home-brewing a version control system is almost certainly a terrible idea, given the existence of good-quality solutions! 考虑到高质量解决方案的存在,自带版本控制系统几乎肯定是一个可怕的主意!

If you'd like some pure java implementatoin for document versioning, maybe you could go for: Jackrabbit 如果您想使用一些纯Java实现来进行文档版本控制,也许您可​​以选择: Jackrabbit

Similar questions have been already asked before. 之前已经提出过类似的问题。 The 1.st answer (marked as correct one) on this question goes for Jackrabbit as well: Using a version control system as a data backend 关于这个问题的第一个答案(标记为正确答案)也适用于Jackrabbit:使用版本控制系统作为数据后端

The simplest possible way would be to use tools diff and patch . 最简单的方法是使用diffpatch工具。 They were used as a core of CVS. 它们被用作CVS的核心。 I assume that you would like to run your application in Windows where they are not preinstalled. 我假设您想在未预安装Windows的Windows中运行您的应用程序。 I don't know whether it would be easy / comfortable to use windows versions of this tools but you can always try to write similiar functionality on your own. 我不知道使用Windows版本的此工具是否容易/舒适,但是您始终可以尝试自己编写类似的功能。 Here you can find very good tutorial about finding differences between files and patching them: http://tuts.pinehead.tv/2012/09/18/introduction-using-diff-and-patch/ When you know the functionality it's quite easy to write something similiar on your own. 在这里,您可以找到有关查找文件之间的差异并对其进行修补的很好的教程: http : //tuts.pinehead.tv/2012/09/18/introduction-using-diff-and-patch/当您知道功能时,这很容易自己写些类似的东西。

I think you should use Git for this, I found a Java API called JavaGit , so you can have easy access the repository. 我认为您应该为此使用Git,我发现了一个名为JavaGit的Java API,因此您可以轻松访问存储库。 With Git you can have a local repository where you can commit files and switch versions. 使用Git,您可以拥有一个本地存储库,可以在其中提交文件和切换版本。 If you need it you could also push and pull the data to a remote location. 如果需要,您还可以将数据推拉到远程位置。

Better use JGit like Gian said! 最好像吉安所说的那样使用JGit

This can be a tricky thing to implement yourself, so I wouldn't recommend it. 实现自己可能是一件棘手的事情,所以我不建议您这样做。

I don't know much about your environment, but if you are able to use an off-the-shelf versioning repository, you'll save yourself much grief. 我对您的环境不太了解,但是如果您能够使用现成的版本控制存储库,则可以避免很多麻烦。 You can try to use Git or SVN directly, which may be the simplest solution for your use case. 您可以尝试直接使用Git或SVN,这可能是针对您的用例的最简单解决方案。

Since you're talking about MS Office files, however, you may be implementing some form of enterprise document management tool. 但是,由于您在谈论MS Office文件,因此您可能正在实现某种形式的企业文档管理工具。 In this case, the JCR specification is designed to provide access to files in a repository, with versioning and other metadata features. 在这种情况下,JCR规范旨在提供对存储库中文件的访问,以及版本控制和其他元数据功能。 Here's the specification . 这是规格

The Apache Jackrabbit project provides an open source implementation of this spec, as does the developers version of Alfresco . Apache Jackrabbit项目以及Alfresco的开发人员版本都提供了此规范的开源实现。

Picking the right solution will really depend on what your users are trying to do with these files, what your deployment environment looks like (don't try to host Git on Windows, k?), and how custom your current codebase is (standard Servlet container? Java EE? home-rolled?). 选择正确的解决方案实际上将取决于您的用户正在尝试使用这些文件,您的部署环境如何(不要尝试在Windows上托管Git,k?)以及您当前代码库的自定义方式(标准Servlet)。容器(Java EE)?

Good luck! 祝好运!

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

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