项目模板 Eclipse/Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2092200/
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
Project templates Eclipse / Java
提问by Valentin
I am researching possibilities to create "project templates" for the kind of projects my team is working on (Embedded Java). We want to make it trivial for a new developer to not mess up creating a new project. All the tools we use in our team should be pr
我正在研究为我的团队正在从事的项目类型(嵌入式 Java)创建“项目模板”的可能性。我们希望让新开发人员不要在创建新项目时陷入困境。我们在团队中使用的所有工具都应该是公关的
The basic idea is that there should be one commandto set up a project and IDE to provide for the following:
基本思想是应该有一个命令来设置项目和 IDE 以提供以下内容:
- Create a new Java project including Eclipse project file.
- Create a Build script (needs to work outside of the IDE).
- Include deploy options in the build script.
- Set up a git project.
- Setup PMD to run with a configured set of rules integrated in the IDE.
- Setup Checkstyle to run with a configured set of rules integrated in the IDE.
- Configure code templates (Eclipse) to match our teams coding guidelines (Javadoc, ...)
- Configure the Eclipse code Formatter.
- The configuration of the command should be upgradeable easily.
- 创建一个包含 Eclipse 项目文件的新 Java 项目。
- 创建一个构建脚本(需要在 IDE 之外工作)。
- 在构建脚本中包含部署选项。
- 设置一个 git 项目。
- 设置 PMD 以使用集成在 IDE 中的一组配置规则运行。
- 设置 Checkstyle 以使用集成在 IDE 中的一组配置规则运行。
- 配置代码模板 (Eclipse) 以匹配我们的团队编码指南(Javadoc,...)
- 配置 Eclipse 代码格式化程序。
- 命令的配置应该可以轻松升级。
So far I see two ways to do this:
到目前为止,我看到了两种方法来做到这一点:
- Maven 2 Archetype: I basically do not like maven because I have been fighting with it so often. I am not sure that the overhead of trying to make the tool do what I want it to justifies the effort. On the other hand it seems like this is exactly what archetypes are supposed to do. Do you have any experience in how far you can customize the eclipse:eclipse part? I guess that the eclipse configuration with be the most complicated step.
- Eclipse Nature: I could create a project nature. As far as I understand the Eclipse Ecosystem that is the component that would show up, if I would choose to provide for something like right click -> New -> My Java Project Type. Do you know how far I can customize the resulting Eclipse project?
- Shell Script: I could create an empty project with all the configuration in place, introduce some special tokens in the relevant plain text files (like and then write a shellscript that reads values for these options from a properties file, copy the project template and substitute the values.). While it is maybe a bit fragile, it seems like a easy and quick way of doing it.
- Maven 2 Archetype:我基本上不喜欢 Maven,因为我经常与它作斗争。我不确定尝试让工具做我想要它做的事情的开销是否证明了努力是合理的。另一方面,这似乎正是原型应该做的。你有什么经验可以自定义 eclipse:eclipse 部分吗?我想 eclipse 配置是最复杂的步骤。
- Eclipse Nature:我可以创建一个项目性质。据我了解 Eclipse 生态系统是将显示的组件,如果我选择提供类似右键单击 -> 新建 -> 我的 Java 项目类型的内容。您知道我可以在多大程度上自定义生成的 Eclipse 项目吗?
- Shell 脚本:我可以创建一个包含所有配置的空项目,在相关的纯文本文件中引入一些特殊标记(例如,然后编写一个从属性文件中读取这些选项值的shell 脚本,复制项目模板并替换价值。)。虽然它可能有点脆弱,但它似乎是一种简单快捷的方法。
Do give you a little more context: It is ok, if the result locks us into Eclipse. While the build should run without Eclipse (for our CI), the Team uses eclipse and it is highly unlikely that we will ever switch. Also all developers run more or less the same Hard+Software (Linux). We don't work in the domain of Enterprise Java Apps so we really don't need all the fancy dependency management stuff from maven. As a matter of fact our build process is so special, that it probably is much easier to just call make or ant scripts.
请给您更多的上下文:没关系,如果结果将我们锁定在 Eclipse 中。虽然构建应该在没有 Eclipse 的情况下运行(对于我们的 CI),但团队使用 Eclipse,而且我们极不可能切换。此外,所有开发人员都或多或少地运行相同的硬件 + 软件 (Linux)。我们不在 Enterprise Java Apps 领域工作,所以我们真的不需要来自 maven 的所有花哨的依赖管理东西。事实上,我们的构建过程非常特殊,调用 make 或 ant 脚本可能要容易得多。
So the Questions are:
所以问题是:
- Do you have any experience with this kind of stuff?
- Do you have an opinion towards either the Eclipse Nature way or Maven?
- Do you know other tools that provide for a setup like that?
- 你对这种东西有什么经验吗?
- 您对 Eclipse Nature 方式或 Maven 有意见吗?
- 您知道其他提供此类设置的工具吗?
Thank you very much for your input.
非常感谢您的意见。
Cheers, Valentin
干杯,瓦伦丁
PS: People seem to be religious about their build tools. Please note that I do not want to start a flamewar here for or against maven. I am sure maven can be a great tool but I think in our context we only need 5% of its functionality and from my experience that remaining 95% can get in your way.
PS:人们似乎对他们的构建工具很虔诚。请注意,我不想在这里开始支持或反对 Maven 的火焰War。我确信 maven 是一个很棒的工具,但我认为在我们的环境中,我们只需要它的 5% 的功能,根据我的经验,剩下的 95% 可能会妨碍你。
采纳答案by Roland Tepp
You can also just create your own PDE tooling project and extend PDE project templates.
您也可以只创建自己的 PDE 工具项目并扩展 PDE 项目模板。
There is a great article at IBM DelevoperWorks network that gives a great introduction to Building templates with the Eclipse Plug-in Development Environment
IBM DelevoperWorks 网络上有一篇很棒的文章,它很好地介绍了使用 Eclipse 插件开发环境构建模板
You can also read up on Eclipse documentation about following PDE extension points:
您还可以阅读有关以下 PDE 扩展点的 Eclipse 文档:
org.eclipse.pde.ui.templates
-- registers plug-in project content templates that are used to generate code for the new extensionsorg.eclipse.pde.ui.newExtension
-- contribute wizards that will be used to create and edit new extensions in PDE plug-in manifest editororg.eclipse.pde.ui.pluginContent
-- provides for contributing wizards that create additional content of the PDE plug-in projects
org.eclipse.pde.ui.templates
-- 注册用于为新扩展生成代码的插件项目内容模板org.eclipse.pde.ui.newExtension
-- 提供将用于在 PDE 插件清单编辑器中创建和编辑新扩展的向导org.eclipse.pde.ui.pluginContent
-- 提供用于创建 PDE 插件项目附加内容的贡献向导
回答by Manius
Whatever you do, for God's sake, don't even think about using the Maven VIRUS for this. Exception: If you hate yourself, and enjoy inflicting needless pain on yourself and others because you get some kind of sick pleasure out of it--then, you should use Maven. If you also prefer to bleed internally while you work, throw in Ivy.
无论你做什么,看在上帝的份上,甚至不要考虑为此使用 Maven 病毒。例外:如果你讨厌自己,并且喜欢给自己和他人造成不必要的痛苦,因为你从中得到了某种病态的快乐——那么,你应该使用 Maven。如果您还喜欢在工作时内部流血,请使用 Ivy。
Eclipse generation IS a good idea (and probably ideal for the end users), but realistically to prevent this turning into such a large project, just go with the simple solution: create a template and use some simple method of customizing it. Just use a find/replace or a simple Python script if really needed. It's hard enough coming up with a complete, solid, re-usable template as it is (a project in itself). Let an Eclipse plug-in or other more automated version come later after you have a better idea of how much work this is.
Eclipse 生成是一个好主意(并且可能是最终用户的理想选择),但实际上为了防止它变成如此大的项目,只需采用简单的解决方案:创建一个模板并使用一些简单的方法对其进行自定义。如果确实需要,只需使用查找/替换或简单的 Python 脚本。想出一个完整的、可靠的、可重用的模板(本身就是一个项目)已经够难的了。让 Eclipse 插件或其他更自动化的版本在您更好地了解这是多少工作之后出现。
The find/replace or script method isn't "fragile" since your template is going to be small and written by a single author, not some massive production application with who knows what inside of it. More complex solutions are the ones which tend to really become fragile, not the simple ones.
find/replace 或 script 方法不是“脆弱的”,因为您的模板很小并且由一个作者编写,而不是一些知道其中内容的大型生产应用程序。更复杂的解决方案往往会变得非常脆弱,而不是简单的解决方案。
I think this is a fantastic idea so don't let anyone tell you otherwise, I create templates like this too.
我认为这是一个绝妙的主意,所以不要让任何人告诉你,我也创建了这样的模板。
回答by Newtopian
Have a look at Gradle, it supports the good stuff from Ivy (dependency management), Maven like Archetypes also.
看看Gradle,它支持来自 Ivy(依赖管理)的好东西,Maven 也像 Archetypes。
Quick question though... how often do you have to create new projects ? Is it really that cumbersome that it would define which build system you would use ?
快速提问……你多久必须创建一个新项目?它会定义您将使用哪个构建系统真的那么麻烦吗?
This being said, I do really like to have a standard project structure, saves a lot of time when trying to decide some stupid things that one should not even have to think about...
话虽如此,我真的很喜欢有一个标准的项目结构,在尝试决定一些甚至不必考虑的愚蠢事情时可以节省大量时间......