• maven pom 引入本地jar包


    maven pom 引入本地jar包

    1. 在pom.xml同级目录下新建lib文件夹,并放入本地jar包。
    2. 配置Jar包的dependency,包括groupId,artifactId,version三个属性,同时还要包含scope和systemPath属性,分别指定Jar包来源于本地文件,和本地文件的所在路径。示例:
    <dependency>
        <groupId>cpdetector</groupId>
        <artifactId>cpdetector</artifactId>
        <version>1.0.10</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/xxx1.0.10.jar</systemPath>
    </dependency>
    

    ${basedir}是指项目根路径。
    3.配置插件将本地jar包打入运行jar/war包中,由于scope=system,默认并不会将Jar包打进jar/war包中,所有需要通过插件进行打包。

       <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope>
                    </configuration>
                </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>compile</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                    <includeScope>system</includeScope>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    4、将依赖jar包打包至jar包中
    方法一:

    <build>
            <finalName>包名</finalName>
            <plugins>
                <!--源码编译-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>包程序主类</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>assembly</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    方法二:生成含依赖xxx.jar包和original-xxx.jar不含依赖jar包。

     <build>
            <finalName>包名</finalName>
            <plugins>
                <!--源码编译-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <!-- shade插件打包成jar包 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <transformers>
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>包程序主类</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>         
            </plugins>
        </build>
    
  • 相关阅读:
    WordPress后台添加友情链接管理功能
    WordPress评论时一键填入昵称、邮箱和网址
    七牛云存储更新缓存图片的方法
    WordPress文章中插入qq表情
    WordPress文章页添加展开/收缩功能
    WordPress添加显示和隐藏侧边栏按钮开关
    Defraggler磁盘碎片整理工具,让你的电脑读写速度更快
    如何彻底关闭系统还原功能和删除系统还原点
    WordPress博客彻底关闭图片缩略图功能的方法
    WP Super Cache+七牛云配置CDN加速,让你的网站秒开
  • 原文地址:https://www.cnblogs.com/lenovo_tiger_love/p/9873755.html
Copyright © 2020-2023  润新知