spring-maven-jar包依赖

博主使用的 apache - maven 版本为 3.6.1,提到 maven 环境配置可自行百度,随后表示会给出一组可用的 jar 包依赖。

我的apache-maven版本是3.6.1,关于maven的环境配置可自行百度。

下面给出一组可用的jar包依赖:

<dependencies>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.2</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.2</version>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>RELEASE</version>
      <scope>compile</scope>
    </dependency>

  </dependencies>

 

### 配置 `spring-boot-maven-plugin` 实现依赖与主程序分离 为了实现依赖与主程序的分离,在项目中的 `pom.xml` 文件内需正确配置 `spring-boot-maven-plugin` 插件。具体而言,通过设置 `<layout>` 参数为 `MODULE` 或者利用自定义分类器来区分应用程序及其依赖项。 #### 使用 MODULE Layout 方式 当采用 `MODULE` layout 选项时,Spring Boot 将创建两个独立的 JAR 文件:一个是含应用本身的可执行 JAR;另一个则是仅含外部库的附加 JAR。这种方式简化了部署流程并允许更灵活地管理版本控制[^1]。 ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>MODULE</layout> </configuration> </plugin> </plugins> </build> ``` #### 自定义分类器方法 另一种做法是借助于 Maven 的内置机制——即使用不同的 classifier 来分别构建带有特定属性的应用程序和其所需的第三方类库集合。这使得开发者能够更加精细地定制最终产物的形式以及它们之间的关系[^2]。 ```xml <build> <plugins> <!-- 构建不含任何依赖的标准JAR --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>${maven-jar-plugin.version}</version> <executions> <execution> <goals> <goal>jar</goal> </goals> <phase>package</phase> <configuration> <classifier>classes-only</classifier> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </configuration> </execution> </executions> </plugin> <!-- 创建含所有依赖的ZIP存档 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>${maven-assembly-plugin.version}</version> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.example.MainApplication</mainClass> </manifest> </archive> <finalName>${project.artifactId}-${project.version}-dependencies</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> </execution> </executions> </plugin> <!-- Spring Boot Plugin Configuration --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 上述代码片段展示了如何通过组合多个插件的功能来达到将依赖项从主应用程序中剥离的效果。这里不仅有标准的 jar过程,还加入了 assembly 插件用于收集所有的依赖到单独的一个压缩文件里去[^3]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水能zai舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值