使用 Maven 和 Eclipse 导出为 Jar 构建项目的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14395568/
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
difference between building project using maven and eclipse export as Jar
提问by pradeep
This sounds like a dumb question but i am really confused with this. I never used maven but i know that it is used to build projects.
这听起来像一个愚蠢的问题,但我真的对此感到困惑。我从未使用过 maven,但我知道它用于构建项目。
So, I have a question : why there is a need of building project using Maven when we can build project in Eclipse (without Maven). Just by exporting the eclipse project as JAR and include required Libraries and all.
所以,我有一个问题:当我们可以在 Eclipse 中构建项目(没有 Maven)时,为什么还需要使用 Maven 构建项目。只需将 eclipse 项目导出为 JAR 并包含所需的库等。
suppose, I download any project from github. Now I can import that project in eclipse and export it as JAR and use it functionality. So why all suggest to use MAVEN to build project and generate binaries and use it.
假设,我从 github 下载任何项目。现在我可以在 Eclipse 中导入该项目并将其导出为 JAR 并使用它的功能。那么为什么都建议使用MAVEN来构建项目并生成二进制文件并使用它。
回答by Bastien Jansen
First of all, not everybody uses Eclipse (even in the same team), and different IDEs could produce slightly different artifacts (JAR files).
首先,并不是每个人都使用 Eclipse(即使在同一个团队中),不同的 IDE 可能会产生略有不同的工件(JAR 文件)。
One advantage of Maven is that it does not only build projects:
Maven 的优势之一是它不仅构建项目:
- it prones convention over configuration, and suggests a "standard" layout for projects
- it allows gathering all the dependencies needed in your project, using specific versions (as opposed to having something like "lib/log4j.jar", no version is specified)
- it allows making lots of different artifacts: JARs containing compiled code or source code, javadoc, WARs, etc.
- it can be run outside of your IDE, very often on a continuous integrationserver
- 它倾向于约定优于配置,并建议项目的“标准”布局
- 它允许使用特定版本收集项目中所需的所有依赖项(而不是像“lib/log4j.jar”这样的东西,没有指定版本)
- 它允许制作许多不同的工件:包含编译代码或源代码的 JAR、javadoc、WAR 等。
- 它可以在您的 IDE 之外运行,通常在持续集成服务器上运行
I would recommend using Maven even for small projects :)
即使对于小型项目,我也建议使用 Maven :)
回答by Dan D.
Because you will soon want to build your project automatically, using automated tools and there will be no Eclipse to help you.
因为您很快就会希望使用自动化工具自动构建您的项目,并且没有 Eclipse 可以帮助您。
Possible stuff you will need soon:
您可能很快需要的东西:
- build your project on every commit to your repository
- build your project on a single click somewhere in a continuous integration tool UI
- your users may not know or care about Eclipse, but they know how to use an UI for issuing a build
- 在每次提交到您的存储库时构建您的项目
- 在持续集成工具 UI 中的某处单击一下即可构建您的项目
- 您的用户可能不知道或不关心 Eclipse,但他们知道如何使用 UI 来发布构建
回答by madhairsilence
Assume a simple real time scenario
假设一个简单的实时场景
Development Environment -> Production Environment (leave testing now)
开发环境 -> 生产环境(现在离开测试)
In dev environment, you will have all dev friendly tools to cut short your effort in writing and spend more time in working on the logic.
在开发环境中,您将拥有所有开发友好的工具来减少您的编写工作并花更多时间处理逻辑。
Once you are done with you part, you will check it into a version control.
一旦你完成了你的部分,你将把它签入版本控制。
This should move to production now. You will check out the latest version from version control into production
这应该现在转移到生产中。您将检查从版本控制到生产的最新版本
Now , you cant have eclipse here too! As you are not going to develop anything. In this, case, a simple pom.xml will be used all the time and the tool called Maven
现在,你也不能在这里有日食!因为你不会开发任何东西。在这种情况下,将始终使用一个简单的 pom.xml 和名为 Maven 的工具
Not all the time, the developer is going to prepare the binaries. So, assume some one who is not a developer is deploying ur app. Instead of asking him to open eclipse and say export blah blah blah, You can just say, run this command/batch file. That batch file will obviously contain the maven commands (mvn compile, mvn package) etc.
并非所有时间,开发人员都会准备二进制文件。因此,假设某个非开发人员正在部署您的应用程序。而不是让他打开 eclipse 并说 export blah blah blah,你可以说,运行这个命令/批处理文件。该批处理文件显然将包含 maven 命令(mvn compile、mvn package)等。
Finally Eclipse is to cut short development time for developers, because, u may end up running maven again and again, due to simple typo-s which can be cut short by eclipse. In production, its one time, run a batch file. Your app is deployed
最后,Eclipse 将缩短开发人员的开发时间,因为您可能会一次又一次地运行 maven,因为可以通过 Eclipse 缩短拼写错误。在生产中,有一次,运行一个批处理文件。您的应用已部署