我们需要先创建一个Mavenpom.xml文件。本pom.xml是用来构建项目的配方。打开您喜欢的文本编辑器并添加以下内容:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <groupId>com.example</groupId>
    6. <artifactId>myproject</artifactId>
    7. <version>0.0.1-SNAPSHOT</version>
    8. <parent>
    9. <groupId>org.springframework.boot</groupId>
    10. <artifactId>spring-boot-starter-parent</artifactId>
    11. <version>2.4.0-SNAPSHOT</version>
    12. </parent>
    13. <description/>
    14. <developers>
    15. <developer/>
    16. </developers>
    17. <licenses>
    18. <license/>
    19. </licenses>
    20. <scm>
    21. <url/>
    22. </scm>
    23. <url/>
    24. <!-- Additional lines to be added here... -->
    25. <!-- (you don't need this if you are using a .RELEASE version) -->
    26. <repositories>
    27. <repository>
    28. <id>spring-snapshots</id>
    29. <url>https://repo.spring.io/snapshot</url>
    30. <snapshots><enabled>true</enabled></snapshots>
    31. </repository>
    32. <repository>
    33. <id>spring-milestones</id>
    34. <url>https://repo.spring.io/milestone</url>
    35. </repository>
    36. </repositories>
    37. <pluginRepositories>
    38. <pluginRepository>
    39. <id>spring-snapshots</id>
    40. <url>https://repo.spring.io/snapshot</url>
    41. </pluginRepository>
    42. <pluginRepository>
    43. <id>spring-milestones</id>
    44. <url>https://repo.spring.io/milestone</url>
    45. </pluginRepository>
    46. </pluginRepositories>
    47. </project>

    上面的清单应为您提供有效的构建。您可以通过运行mvn package进行测试(目前,您可以忽略“ jar文件将为空-没有标记包含的内容(jar will be empty - no content was marked for inclusion!)”警告)。

    info.svg 此时,您可以将项目导入到IDE中(大多数现代Java IDE都包含对Maven的内置支持)。为简单起见,我们在此示例中继续使用纯文本编辑器。