直接先上图,使用IDEA创建的普通JAVA项目结构如下:
可以看到普通java项目除了一个src及配置信息外,空空如也。通过IDEA工具创建Maven项目
创建的项目结构如下:
多了一个pom.xml文件,并且src文件夹中自动创建了main/java、main/resources等文件夹,方便管理。很明显使用maven来管理项目更加方便管理。同样各种开发环境都有各种的包管理工具,如PHP中会使用Composer,nodejs使用npm,android开发常用Gradle方式来进行包依赖管理。
由于之前项目是普通项目,所以需要将其转换为Maven项目,在IDEA实现转换很简单,主要有以下方法:
右键选项 “Add Framework Support”,如下:
然后设置maven相关信息:
最后编辑下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.0modelVersion>
<groupId>jstudy.mybatisgroupId>
<artifactId>java-mybatis-tinyartifactId>
<version>1.0-SNAPSHOTversion>
<properties>
<maven.compiler.source>14maven.compiler.source>
<maven.compiler.target>14maven.compiler.target>
properties>
project>
至此,转换完毕。
在项目根目录下添加pom.xml,并将上面内容粘贴,IDE工具将会自动识别maven项目,然后点击同步下项目:
转换完毕。
由于使用maven管理项目,顺便将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.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.7.4version>
<relativePath />
parent>
<groupId>org.examplegroupId>
<artifactId>learn-pomartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>jarpackaging>
<dependencies>
<dependency>
<groupId>io.springfoxgroupId>
<artifactId>springfox-boot-starterartifactId>
<version>3.0.0version>
<type>jartype>
<scope>testscope>
<systemPath>systemPath>
<optional>trueoptional>
<exclusions>
<exclusion>
<groupId>io.springfoxgroupId>
<artifactId>springfox-boot-teseterartifactId>
exclusion>
exclusions>
dependency>
dependencies>
<dependencyManagement>dependencyManagement>
<properties>
<sf.version>2.0.0sf.version>
properties>
<modules>
<module>project-1module>
<module>project-2module>
<module>project-3module>
modules>
<build>
<defaultGoal>installdefaultGoal>
<directory>${basedir}/targetdirectory>
<sourceDirectory>${basedir}/src/main/javasourceDirectory>
<scriptSourceDirectory>${basedir}/src/main/scriptsscriptSourceDirectory>
<outputDirectory>${basedir}/target/classesoutputDirectory>
<testOutputDirectory>${basedir}/target/test-classestestOutputDirectory>
<testSourceDirectory>${basedir}/src/test/javatestSourceDirectory>
<finalName>myproject-SNAPSHOTfinalName>
<filters>
<filter>myproject.propertiesfilter>
filters>
<extensions>
<extension>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.30version>
extension>
extensions>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<extensions>falseextensions>
<inherited>trueinherited>
<dependencies>dependencies>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
exclude>
excludes>
configuration>
<executions>
<execution>
<id>testerid>
<goals>
<goal>rungoal>
goals>
<inherited>falseinherited>
<configuration>configuration>
execution>
executions>
plugin>
plugins>
<pluginManagement>pluginManagement>
build>
<reporting>
<plugins>plugins>
reporting>
<name>learn pomname>
<description>just learn pom projectdescription>
<inceptionYear>2020inceptionYear>
<url>https://github.com/url>
<licenses>
<license>
<name>My Licensename>
<distribution>githubdistribution>
<url>https://github.com/url>
<comments>Just my Licensecomments>
license>
licenses>
<organization>
<name>My Corname>
<url>https://github.com/url>
organization>
<developers>
<developer>
<id>masterid>
<name>hunkxianame>
<email>hunk.xia@gmail.comemail>
<organization>My Cororganization>
<organizationUrl>https://github.com/organizationUrl>
<roles>
<role>masterrole>
roles>
<properties>properties>
developer>
developers>
<contributors>contributors>
<issueManagement>
<system>isssystem>
<url>https://github.com/url>
issueManagement>
<ciManagement>
<system>cissystem>
<url>https://github.com/url>
<notifiers>
<notifier>
<type>mailtype>
<sendOnError>truesendOnError>
<sendOnFailure>truesendOnFailure>
<sendOnSuccess>truesendOnSuccess>
<sendOnWarning>truesendOnWarning>
<address>hunk.xia@gmail.comaddress>
<configuration>configuration>
notifier>
notifiers>
ciManagement>
<mailingLists>
<mailingList>
<name>list-1name>
<subscribe>subscribe>
<unsubscribe>unsubscribe>
<post>post>
<archive>archive>
<otherArchives>otherArchives>
mailingList>
mailingLists>
<scm>
<connection>connection>
<developerConnection>developerConnection>
<tag>HEADtag>
<url>url>
scm>
<prerequisites>prerequisites>
<repositories>
<repository>
<id>my reposid>
<name>My Repositoryname>
<url>http://repo.myrepos.cn/content/groups/public/url>
<releases>
<enabled>trueenabled>
<updatePolicy>dailyupdatePolicy>
releases>
<snapshots>
<enabled>trueenabled>
<checksumPolicy>warnchecksumPolicy>
snapshots>
<layout>defaultlayout>
repository>
repositories>
<pluginRepositories>pluginRepositories>
<distributionManagement>
<repository>repository>
<site>site>
<downloadUrl>downloadUrl>
<status>status>
distributionManagement>
<profiles>
<profile>
<id>releaseid>
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*include>
includes>
resource>
resources>
build>
profile>
<profile>
<id>testid>
<build>
<resources>
<resource>
<directory>src/test/resourcesdirectory>
<includes>
<include>config/*.propertiesinclude>
<include>log4j.xmlinclude>
includes>
resource>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.xmlinclude>
includes>
<excludes>
<exclude>log4j.xmlexclude>
excludes>
resource>
resources>
build>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
profile>
profiles>
project>
本篇完,下次再深入讲解和研究下多项目(父子项目、依赖项目)如何规范配置。