Linux 如何使用Maven管理项目依赖?

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

How to manage project dependencies using Maven?

javalinuxmaven

提问by dudemonkey

This is probably a newbie quesiton, but I'm a newbie when it comes to Java and the Maven documentation is tough to work through and all seems to be written for Maven experts. I'm trying to install a driver in a Java project. I've got a project with code that works (ie, I don't want to torch what I already have) and maven is installed and up-to-date. I know the dependency XML to add to pom.xml, but I don't know where to start to create a pom.xml file.

这可能是一个新手问题,但我是 Java 新手,而且 Maven 文档很难完成,而且似乎都是为 Maven 专家编写的。我正在尝试在 Java 项目中安装驱动程序。我有一个代码可以工作的项目(即,我不想烧掉我已经拥有的东西)并且 maven 已经安装并且是最新的。我知道要添加到 pom.xml 的依赖关系 XML,但我不知道从哪里开始创建 pom.xml 文件。

I tried to run 'mvn install' a couple of times, but I don't see the driver anywhere so I can't reference it with my java build path.

我试图运行“mvn install”几次,但我在任何地方都没有看到驱动程序,所以我无法用我的 java 构建路径引用它。

What's the best way to proceed?

最好的方法是什么?

采纳答案by user

First of all check if the maven is installed - mvn --versionin the command line.

首先检查是否安装了 Maven -mvn --version在命令行中。

If not - follow the guide - http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

如果没有 - 按照指南 - http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

To create a pom.xmlmanually is not a good point if you use IDE - just create a new Maven project (for example in Idea or Eclipse). This way you will avoid errors with some required configurational tags missing. Then add the needed dependency in the dependenciestag in pom.xml

pom.xml如果您使用 IDE,手动创建一个不是一个好点 - 只需创建一个新的 Maven 项目(例如在 Idea 或 Eclipse 中)。这样您就可以避免一些必需的配置标签丢失的错误。然后在dependencies标签中添加所需的依赖项pom.xml

Actually, one of the best tutorials about maven is http://www.mkyong.com/tutorials/maven-tutorials/- there are a lot of topics. Choose the desired one.

实际上,关于 maven 的最佳教程之一是http://www.mkyong.com/tutorials/maven-tutorials/- 有很多主题。选择所需的一项。

If you use Eclipse IDEjust follow this tutorial to convert your project to the Maven project - Convert Existing Eclipse Project to Maven Project- and delete the pom.xmlcreated by you before that. Be sure to have the m2eclipseplugin installed in the IDE.

如果您使用Eclipse IDE只需按照本教程将您的项目转换为 Maven 项目 - Convert Existing Eclipse Project to Maven Project- 并删除pom.xml您之前创建的。确保m2eclipse在 IDE 中安装了插件。

This is for the conversion in the Intellij idea- IntelliJ - Convert a Java project/module into a Maven project/module

这是用于转换Intellij idea- IntelliJ - Convert a Java project/module into a Maven project/module