美文网首页
maven引入本地jar包,运行时报错"java.lang.No

maven引入本地jar包,运行时报错"java.lang.No

作者: Kyriez7 | 来源:发表于2022-10-09 09:48 被阅读0次

    下文笔者讲述maven引入本地jar包时,运行报错"java.lang.NoClassDefFoundError"的处理方法分享,如下所示

    今天在编写maven项目
    导入本地jar包
    部署到服务器上找不到包
    报错信息如:java.lang.NoClassDefFoundError

    那么如何解决呢?
    这种问题是由于,本地jar包在打包的时,没有打入到
    项目中,我们只需在maven打包时,告诉maven项目
    需把这个jar包打入即可
    maven引入本地jar的示例

    <dependency>
    <groupId>com.java265</groupId>
    <artifactId>test-core-SNAPSHOT.jar</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${pom.basedir}/src/main/resources/lib/test-core-SNAPSHOT.jar</systemPath>
    </dependency>
    配置maven将本地jar打入package中

    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <includeSystemScope>true</includeSystemScope>
    </configuration>
    </plugin>
    maven打包知识分享

    maven打包可以控制是否需要将jar打入
    可使用scope标签
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    scope详解

    缺省的scope,其值为scope=compile
    参数 备注 是否会被打入package中jar
    compile 默认scope 是
    test 测试使用 否
    provided 编译需要 否
    runtime 编译不需要,运行时需要 是
    system 加载本地jar 否

    相关文章

      网友评论

          本文标题:maven引入本地jar包,运行时报错"java.lang.No

          本文链接:https://www.haomeiwen.com/subject/ysjgartx.html