[英]How do I add a Maven pom.xml to an existing project without using an IDE?
I have an existing Java project with a single dependency. 我有一个具有单一依赖项的现有Java项目。 I just want to make a pom.xml so that someone can pull the project,
mvn install
or mvn init
or whatever it is, then start working. 我只想制作一个pom.xml,以便有人可以拉动项目,
mvn install
或mvn init
或者它是什么,然后开始工作。 How do I do this without using an IDE? 如何在不使用IDE的情况下执行此操作?
I'm looking for the equivalent of pip freeze
or npm init
, or just what I can copy and paste into a new pom.xml
file. 我正在寻找相当于
pip freeze
或npm init
,或者我可以复制并粘贴到新的pom.xml
文件中。
I tried Googling and only found stuff for starting new projects with Maven or using an Eclipse plugin. 我尝试使用Googling,只找到了使用Maven或使用Eclipse插件启动新项目的东西。
You seem to be looking for a Minimal POM for your project. 您似乎正在为您的项目寻找最小POM 。 This is defined as -
这被定义为 -
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
where you can replace the names more convenient to your group
and artifact
. 您可以在其中替换更适合您的
group
和artifact
的名称。 Just a small note to take care of - 只是一个小小的注意事项 -
..if the configuration details are not specified, Maven will use their defaults.
..如果未指定配置详细信息,Maven将使用其默认值。
Follow suggested three steps to convert your project into maven project. 按照建议的三个步骤将项目转换为maven项目。
Step 1: As suggested by nullpointer , following attributes are mandatory in your pom to make it as maven project. 第1步:正如nullpointer所建议的那样 ,pom中必须使用以下属性才能将其作为maven项目。
Sample pom.xml file : 示例pom.xml文件 :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.infy</groupId>
<artifactId>user-identity-rest</artifactId>
<version>1.0.0</version>
</project>
groupId : It is unique identifier to the group of multiple modules in your project groupId :它是项目中多个模块组的唯一标识符
artifactId : Unique module identifier of your module. artifactId :模块的唯一模块标识符。
version : Initially we will start with version 1.0.0 and will upgrade to 1.0.1 and so on subsequently. version :最初我们将从版本1.0.0开始,然后将升级到1.0.1等等。
You can customized these things as per your understanding and future references. 您可以根据您的理解和未来参考来定制这些东西。
Step 2: Now you need to add all libraries in declared pom.xml which is similar to jars you added in your project. 第2步:现在您需要在声明的pom.xml中添加所有库,这类似于您在项目中添加的jar。
You might have added a library in your project(lets say json-simple-1.1.1.jar). 您可能在项目中添加了一个库(比如说json-simple-1.1.1.jar)。 Here maven doesn't look for the whole library, instead it asks its dependency.
这里maven不会查找整个库,而是询问它的依赖性。
You can find dependency of your external library here by searching for library with exact version . 您可以通过搜索具有确切版本的库来查找外部库的依赖关系。
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Now you need to copy the dependency from given site and paste it to your pom.xml file within the <dependencies>
element. 现在,您需要从给定站点复制依赖项并将其粘贴到
<dependencies>
元素中的pom.xml文件中。 In this example, the full pom.xml is: 在此示例中,完整的pom.xml是:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.infy</groupId>
<artifactId>user-identity-rest</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
Maven will automatically fetch it from its repository. Maven将自动从其存储库中获取它。
Step 3: Third and last step is to build your project. 第3步:第三步也是最后一步是构建您的项目。 Open command prompt/terminal and go to the directory where your pom.xml is declared and type mvn clean install
打开命令提示符/终端并转到声明pom.xml的目录,然后键入mvn clean install
This will generate an executable for your project on local and voilla! 这将为本地和voilla的项目生成可执行文件! You have converted and built your project into maven project
您已将项目转换并构建到maven项目中
Reference Path: C:\\PA\\IntelliJ Workspace\\Springboot Practise\\target\\spring-boot-examples-1.0-SNAPSHOT.jar 参考路径:C:\\ PA \\ IntelliJ工作区\\ Springboot练习\\目标\\ spring-boot-examples-1.0-SNAPSHOT.jar
Note: Comment below if you need more clarifications. 注意:如果您需要更多说明, 请在下方注释。
You can let Maven create the pom.xml
and directory structure for you auomatically with this command: 您可以让Maven使用以下命令自动为您创建
pom.xml
和目录结构:
$ mvn archetype:generate -DgroupId=com.mkyong -DartifactId=NumberGenerator -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
But just replace the groupId
and artifactId
with your own values. 但只需用您自己的值替换
groupId
和artifactId
。
Then put your .java
files in /src/main/java/com/mkyong
. 然后将
.java
文件放在/src/main/java/com/mkyong
。
And then run the standard commands like mvn compile
, mvn clean
, mvn package
. 然后运行标准命令,如
mvn compile
, mvn clean
, mvn package
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.