如何将springboot 工程的依赖包打包到一个目录

1)    将 system scope 的jar 安装到自己的本地mvn rep, 执行一次即可 ,可以在idea or  eclipse 里面执行 run maven   


2)   @Primary
       @Bean(name="postgresSqlSessionFactory") 
        public SqlSessionFactory postgresSqlSessionFactory(@Qualifier("postgresDataSource") DataSource dataSource) throws Exception  { 
               SqlSessionFactoryBean b = new SqlSessionFactoryBean();
              b.setDataSource(dataSource);
              b.setMapperLocations(new PathMatchingResourcePatternResolver()
                       .getResources("classpath*:/com/xxx/yyy/db/**/*Mapper.xml"));   //一定不要写成 **/*Mapper.xml springboot 会无法找到 依赖jar 里面的xml
                
               b.setConfigLocation(new PathMatchingResourcePatternResolver()
                       .getResources("classpath:mybatis-config-postgres.xml")[0]); 
               
               return b.getObject();    
   }

3) 编译:  -DisCloudVersion=true or -DisCloudVersion=false  来区分 cloud 和onpromise 编译 
                 

4)  部署:
       将 *onpromise.jar 放置在一个目录(当前就是这么干的),同级目录新建 lib 目录,将编译生成的 lib 里面的jar 拷贝过去即可, 启动方式和现在一致, 记得启动命令将 -exec.jar 后缀改成 -onpromise.jar

5) 重点讲解: 
            <profile>
                                                            <id>onpromise</id>
                                                            <activation>
                                                                            <property>
                                                                                            <name>isCloudVersion</name>
                                                                                            <value>false</value>
                                                                            </property>
                                                            </activation>
                                                            <build>
                                                                           <plugins>
                                                                                           <plugin>
                                                                                                           <groupId>org.apache.maven.plugins</groupId>
                                                                                                           <artifactId>maven-dependency-plugin</artifactId> // 完成依赖 jar 的 copy
                                                                                                           <executions>
                                                                                                                           <execution>
                                                                                                                                           <id>copy</id>
                                                                                                                                           <phase>package</phase>
                                                                                                                                           <goals>
                                                                                                                                                           <goal>copy-dependencies</goal>
                                                                                                                                           </goals>
                                                                                                                                           <configuration>
                                                                                                                                                           <outputDirectory>${project.build.directory}/../../lib</outputDirectory>
                                                                                                                                                           <includeScope>compile</includeScope>
                                                                                                                                                           <includeScope>provided</includeScope>
                                                                                                                                                           <includeScope>system</includeScope>
                                                                                                                                                           <includeScope>runtime</includeScope>
                                                                                                                                           </configuration>
                                                                                                                           </execution> 
                                                                                                           </executions>
                                                                                           </plugin>
           
                                                                                           <plugin>
                                                                                                           <groupId>org.apache.maven.plugins</groupId>
                                                                                                           <artifactId>maven-jar-plugin</artifactId>
                                                                                                           <configuration>
                                                                                                                           <includeSystemScope>true</includeSystemScope>  
                                                                                                                           <archive>
                                                                                                                                           <manifest> 
                                                                                                                                                           <mainClass>com.xxx.yyy.Application</mainClass>    // 完成依赖 MANIFEST Class-Path 的赋值
                                                                                                                                                           <classpathPrefix>./lib</classpathPrefix>
                                                                                                                                                           <addClasspath>true</addClasspath>
                                                                                                                                           </manifest>
                                                                                                                           </archive> 
                                                                                                                           <excludes>
                                                                                                                                           <exclude>bin/**</exclude>
                                                                                                                                           <exclude>config/**</exclude>
                                                                                                                                           <exclude>logs/**</exclude>
                                                                                                                           </excludes>
                                                                                                           </configuration>
                                                                                           </plugin>
           
           
                                                                                           <plugin>
                                                                                                           <groupId>org.springframework.boot</groupId>
                                                                                                           <artifactId>spring-boot-maven-plugin</artifactId>
                                                                                                           <configuration>
                                                                                                                           <mainClass>com.xxx.yyy.Application</mainClass>
                                                                                                                           <includeSystemScope>true</includeSystemScope>
                                                                                                                           <layout>ZIP</layout>
                                                                                                                           <includes>
                                                                                                                                           <include>
                                                                                                                                                           <groupId>nothing</groupId>    // 去除对 依赖 jar 的整体打包
                                                                                                                                                           <artifactId>nothing</artifactId>
                                                                                                                                           </include>
                                                                                                                           </includes>
                                                                                                           </configuration>
                                                                                                           <executions>
                                                                                                                           <execution>
                                                                                                                                           <goals>
                                                                                                                                                           <goal>repackage</goal>
                                                                                                                                           </goals>
                                                                                                                                           <configuration>
                                                                                                                                                           <classifier>onpromise</classifier>
                                                                                                                                           </configuration>
                                                                                                                           </execution>
                                                                                                           </executions>
                                                                                           </plugin>
           
           
                                                                           </plugins>
                                                                           <resources>
                                                                                           <resource>
                                                                                                           <filtering>true</filtering>
                                                                                                           <directory>**</directory>
                                                                                                           <excludes>
                                                                                                                           <exclude>**/application.properties</exclude>
                                                                                                                           <exclude>**/*.proto</exclude>
                                                                                                           </excludes>
                                                                                           </resource>
                                                                           </resources>
                                                           </build>
           
           
                                           </profile>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值