九、Maven项目管理

2022-07-30  本文已影响0人  东方奇迹

https://search.maven.org
https://developer.aliyun.com/mvn/view
Maven输出Jar包插件:maven-assembly-plugin
Maven输出War包插件:maven-war-plugin
IDEA创建基础Maven项目并配置WEB环境?

截屏2022-07-17 下午5.46.53.png

pom.xml文件配置:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>mavenapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!-- packaging代表输出的格式jar或war,默认是jar -->
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <!--    如果想使用其它代理仓库,可在<repositories></repositories>节点中加入对应的仓库使用地址。以使用 spring 代理仓为例:-->
    <!--    配置后会优先从阿里云地址上进行下载,如果阿里云的私服没有的话则会去maven官网进行下载-->
    <!--    提高下载速度-->
    <!--    创建私服的地址-->
    <repositories>
        <repository>
            <id>spring</id>
            <url>https://maven.aliyun.com/repository/spring</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>aliyun</id>
            <name>aliyun</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.29</version>
        </dependency>
        <dependency>
            <groupId>com.belerweb</groupId>
            <artifactId>pinyin4j</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.22</version>
        </dependency>
    </dependencies>
    <build>
        <!--        配置文件-->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.imooc.maven.PinyinTestor</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <!-- all in one ,在打包时会将所有引用的jar合并到输出的jar文件中-->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

    <build>
        <finalName>maven-web</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
        </plugins>
    </build>

上一篇 下一篇

猜你喜欢

热点阅读