spring boot引入本地jar

問題描述:spring boot引入到本地jar到项目(阿里云短信),使用maven package打包,出现以下异常

2017-07-29 00:07:43,822 ERROR SpringApplication:827 - Application startup failed
java.lang.NoClassDefFoundError: com/aliyuncs/profile/IClientProfile
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getDeclaredMethods(Unknown Source)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)

NoClassDefFoundError,解压打包好的jar发现lib里面没有导入本地的两个jar,故怀疑是maven打包出现问题。搜索资料发现,将pom添加以下插件可解决。

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </resources>
    </build>

targetPath:jar输出的目录(相对于项目根目录)
directory:为需要导入的jar的路径

参考链接:https://segmentfault.com/q/1010000007220339

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读