最近在用springboot集成kettle做数据传输,kettle依赖的jar包在阿里云仓库没有,因此从kettle文件夹下面找到了相关包,放在项目resources/lib目录下,想通过本地引用的方式依赖。目录如下图
在这里插入图片描述
引用方式则需要在pom中进行配置,其中project.basedir是一个常量,标识和pom同级目录,这个使用就好了不用设置。

 <dependency>
            <groupId>pentaho-kettle</groupId>
            <artifactId>kettle-core</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/src/main/resources/lib/kettle-core-7.1.0.0-12.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>pentaho-kettle</groupId>
            <artifactId>kettle-engine</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/src/main/resources/lib/kettle-engine-7.1.0.0-12.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>pentaho-kettle</groupId>
            <artifactId>vfs2</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/src/main/resources/lib/commons-vfs2-2.1-20150824.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>pentaho-kettle</groupId>
            <artifactId>metastore</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/src/main/resources/lib/metastore-7.1.0.0-12.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>pentaho-kettle</groupId>
            <artifactId>scannotation</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/src/main/resources/lib/scannotation-1.0.2.jar</systemPath>
        </dependency>

到这一步,项目中已经可以正常使用这些依赖了,当然还有一个解决办法,就是将这些包上传到本地maven仓库,然后正常依赖下载也可以,可以通过如下命令进行上传,需要改变以下路径。

mvn install:install-file -Dfile=/Users/scott/middleware/data-integration/lib/commons-vfs2-2.1-20150824.jar -DgroupId=pentaho-kettle -DartifactId=vfs2 -Dversion=2.1-20150824 -Dpackaging=jar

mvn install:install-file -Dfile=/Users/scott/middleware/data-integration/lib/kettle-core-7.1.0.0-12.jar -DgroupId=pentaho-kettle -DartifactId=kettle-core -Dversion=7.1.0.0-12 -Dpackaging=jar

mvn install:install-file -Dfile=/Users/scott/middleware/data-integration/lib/kettle-engine-7.1.0.0-12.jar -DgroupId=pentaho-kettle -DartifactId=kettle-engine -Dversion=7.1.0.0-12 -Dpackaging=jar

mvn install:install-file -Dfile=/Users/scott/middleware/data-integration/lib/metastore-7.1.0.0-12.jar -DgroupId=pentaho-kettle -DartifactId=metastore -Dversion=7.1.0.0-12 -Dpackaging=jar

mvn install:install-file -Dfile=/Users/scott/middleware/data-integration/lib/scannotation-1.0.2.jar -DgroupId=pentaho-kettle -DartifactId=scannotation -Dversion=1.0.2 -Dpackaging=jar

由于我们没有私有仓库,所以还是得使用本地依赖的方式所以使用了第一种方式。但是当项目启动时,发现无法找到依赖的类,报错classnotfound,于是我解压了通过maven编译的jar包,发现这些本地依赖包没有在其中。这个时候我们需要在maven编译的插件中增加一个配置,如下:
在这里插入图片描述

<includeSystemScope>true</includeSystemScope>

这里解释一下,加入该配置,maven在打包时才会引入外部jar包,比如咱们在resouces/lib目录下面的jar包。
这个时候再进行编译打包。进入target目录,我是macos系统使用tar -xvf 进行解压
此时我们进入/target/BOOT-INF/lib 目录下进行搜索
在这里插入图片描述
通过搜索结果可以发现,外部依赖包已经全部编译至我们打的jar包中,并且jar包能完美启动。
看完有用点个关注,谢谢。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐