Extended use of maven

Table of contents

Add jars that are not in the central warehouse (or custom) to the project as dependencies (idea version)

Package external/custom jar dependencies together into the jar package


Add jars that are not in the central warehouse (or custom) to the project as dependencies (idea version)

Recently, when using kettle for secondary development, many dependencies are no longer in maven's central warehouse, and they are no longer the company's private server, so I keep reporting errors when packaging projects:

 But it can be downloaded to the local warehouse through dependencies , but this error is reported when packaging, so I plan to introduce this dependency manually.

Dependency on the official website: You can download this dependency locally, but the dependency cannot be resolved or cannot be found in the warehouse when an error is reported when packaging;

        <dependency>
			<groupId>pentaho</groupId>   
			<artifactId>pentaho-s3-vfs</artifactId>    
			<version>7.1.0.12-132</version>         
		</dependency>

First download the dependencies of this jar (there are generally resources on the Internet), here I did not use the maven command installation mode, but completed it through lib depending on the pom configuration:

1. Introduce the jar package dependency in the pom.xml file of the project

<dependency>
    <groupId>pentaho</groupId>     <!-- 可以自定义 -->
    <artifactId>pentaho-s3-vfs</artifactId>    <!-- jar名称 -->
    <version>7.1.0.12-132</version>   <!-- 与jar包中定义的版本一致,如果其没有指定,那么这里可以自定义-->
    <type>jar</type>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/lib-s3/pentaho-s3-vfs-7.1.0.12-132.jar</systemPath>    <!-- 使用jar所在的绝对路径 -->
</dependency>

2. Create a lib-s3 file in idea as a dependency (consistent with the path above)

First create the lib-s3 folder in the resource directory:

Note that it is created under the resource directory of src : here I named it lib-s3: then copy the relevant jar package to this lib-s3 file:

 Then set the import dependency in the idea:

 Note: If there is no add as library option, it means that the files in the resource directory in your maven module may be used as dependencies by default. You can put the dependent packages directly into the folder you created. Then see if it can be cited.

 Refresh the pom file. After success , the jar package can be expanded:

 Then use maven to package and test it, and found that it is indeed usable.

Package external/custom jar dependencies together into the jar package

Recently, I am learning to carry out secondary development of kettle. When using the classes in the code defined by myself, I may need to use some other external jars, but simply using maven for packaging cannot package the corresponding jars into the project. Yes, so when the jar is deployed, there will be an error that the dependent class file does not exist, so the external jar needs to be packaged together into the jar package:

Package the external dependencies together into the jar package:

Modify the pom file:

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>xxx-xxx-sdk</finalName>
                    <descriptorRefs>
                        <!-- 将依赖的jar包中的class文件打进生成的jar包-->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!-- 可以增加main函数入口,可有可无-->
                            <mainClass>com.xxx.xxx.xxx</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

After the configuration is complete, execute:  

Reference blog: maven packaging will depend on the jar package

Guess you like

Origin blog.csdn.net/weixin_53142722/article/details/126781342