Spring boot 整合 maven 配置文件pom.xml

本文档记录了Spring Boot项目中maven配置文件pom.xml的关键设置,包括连接maven私服、设定JDK1.7编译、排除依赖包并生成lib目录、打包时排除配置文件及日志文件,以及将代码部署到maven私服的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

仅作为项目模板,备忘,避免重复采坑,不解说。 

主要包含:

    1.项目依赖到maven私服相关配置,除此之外还需要设置maven配置文件setting.xml

    2.编译项目使用jdk1.7

    3.打包项目去除依赖包,并生成lib文件。

    4.打包时去除配置文件和日志文件,后台微服务的服务器配置文件和日志配置文件统一从远程拉取。

    5.项目依赖到maven私服时,将代码也放上去。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.19.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>dubbo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>dubbo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
        </dependency>

    </dependencies>
    <!-- maven私服 -->
    <distributionManagement>
        <repository>
            <id>maven-test-releases</id>
            <name>maven-test-releases</name>
            <url>http://127.0.0.1:8081/repository/maven-test-release/</url>
        </repository>
        <snapshotRepository>
            <id>maven-test-snapshot</id>
            <name>maven-test-snapshot</name>
            <url>http://127.0.0.1:8081/repository/maven-test-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>
    <build>
        <plugins>
            <!-- 使用java jdk1.7编译 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <!-- 打包jar时,去除依赖,并生成lib -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.basedir}/src/main/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <excludeArtifactIds>slf4j-log4j12</excludeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- 去除配置文件和日志文件 -->
            <!--
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <excludes>-->
                        <!-- 后台微服务的服务器配置文件和日志配置文件统一从远程拉取,所以打包的时候要排除掉 --><!--
                        <exclude>application.properties</exclude>
                        <exclude>logback.xml</exclude>
                    </excludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>src/main/lib/</classpathPrefix>
                            <mainClass>com.example.dubbo.DubboApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            -->
            <!-- 要将源码上传至maven私服,需要加入这个插件 -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值