简体   繁体   中英

Add 3rd Party Jars with Maven Package

I have a very simple spring boot project and I use a 3rd party jar named jsoup.

When I run the project from Eclipse, the code is working fine. But when I use mvn clean package command and export it to an executable jar; project still works, but the parts that i use jsoup throws an exception that jsoup cannot be found. So my executable jar does not contains jsoup.

I searched and tried some methods but they did not work. If you can help me i will appreciate it.

Here is my pom file,

<modelVersion>4.0.0</modelVersion>

<groupId>com.tools</groupId>
<artifactId>parser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>parser</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <scope>system</scope>
        <version>1.0</version>
        <systemPath>${basedir}\src\lib\jsoup-1.10.1.jar</systemPath>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

You are using JSoup version 1.10.1 but use it with <scope>system</scope> . Maven doesn't include those jars in the artifacts build, just like <scope>provided</scope> . See also this Stackoverflow question and answers.

However JSoup is a normal jar like your other dependencies and is in Maven Central. As you can see here . Just add it as a regular dependency.

<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.10.1</version>
</dependency>

Instead of what you have now. This will make it be included into your executable jar that Spring Boot will create for you. (And saves you from manually looking for that jar and updates etc.).

In case when your 3-rd party jar has no Maven support and is not in any Maven repository, from where you can download it you need to make a Maven artifact for it and then deploy it into some Maven repository with Maven deploy plugin.

It can be your local repository, your company repository or any public repository you'd like to use.

please see it at: Guide to deploying 3rd party JARs to remote repository

that is a Maven command format from it:

mvn deploy:deploy-file -DgroupId=<group-id> \
 -DartifactId=<artifact-id> \
 -Dversion=<version> \
 -Dpackaging=<type-of-packaging> \
 -Dfile=<path-to-file> \
 -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
 -Durl=<url-of-the-repository-to-deploy>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM