Java 从现有项目生成 Maven POM?

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

Generating a Maven POM from an existing project?

javamaven-2ide

提问by dshaw

Do any of the IDEs (or any other tool for that matter) have the ability to generate a POM based on an existing project?

是否有任何 IDE(或任何其他与此相关的工具)能够基于现有项目生成 POM?



I ended up generating the POM with a Maven archetype as Peterand Salsuggested and then moving the existing source in. Thanks for the help guys.

我最终按照PeterSal 的建议使用 Maven 原型生成 POM,然后将现有源代码移入。感谢各位的帮助。

采纳答案by Peter Lawrey

You can do this in IntelliJ, but the POM it generates may be more complex than if you write by hand. If your project is currently in JBuilder or Eclipse you can import this first.

您可以在 IntelliJ 中执行此操作,但它生成的 POM 可能比您手动编写更复杂。如果您的项目当前在 JBuilder 或 Eclipse 中,您可以先导入它。

Instead I would suggest you describe your project in a POM and use it to generate your project information. You can do this for eclipse and idea (and I assume other IDEs)

相反,我建议您在 POM 中描述您的项目并使用它来生成您的项目信息。您可以为 eclipse 和 idea 执行此操作(我假设其他 IDE)

回答by Pyrolistical

Your existing project probably does not use Maven, so creating a POM based on it isn't trivial.

您现有的项目可能不使用 Maven,因此基于它创建 POM 并非易事。

The simplest way I can think of is to get the Maven plugin for Eclipse, generate a new maven project and then add your code.

我能想到的最简单的方法是获取Eclipse的Maven插件,生成一个新的maven项目,然后添加你的代码。

You'll also need to manage external jars using Maven's method. In this case, they would probably be system jars.

您还需要使用 Maven 的方法管理外部 jar。在这种情况下,它们可能是系统 jar。

回答by sal

One way to do this it to create a template project via maven archetype then move your existing code to the template. I would recommend this only for really simple projects. It would work something like this.

一种方法是通过 maven 原型创建模板项目,然后将现有代码移动到模板。我只会为非常简单的项目推荐这个。它会像这样工作。

mvn archetype:generate 
mv src/* src/main/java
mv test/* src/test/java
mvn package

You'll get errors. To add the missing dependencies, go here: http://www.mvnrepository.com/and start looking them up. If you pick an archetype close to what you need, you'll be half way there.

你会得到错误。要添加缺少的依赖项,请访问:http: //www.mvnrepository.com/并开始查找它们。如果您选择一个接近您需要的原型,您就成功了一半。

Once it all works.

一旦一切正常。

svn commit -m "hacky maven port"

回答by ozone

In eclipse Galileo if you have the maven2 plugin you can select the project and then right click and go down to Maven2 in the context menu and there should be an option to convert the project to a maven project.

在 Eclipse Galileo 中,如果您有 maven2 插件,您可以选择项目,然后右键单击并在上下文菜单中转到 Maven2,应该有一个选项可以将项目转换为 maven 项目。