简体   繁体   English

添加带有Maven软件包的3rd Party Jars

[英]Add 3rd Party Jars with Maven Package

I have a very simple spring boot project and I use a 3rd party jar named jsoup. 我有一个非常简单的spring boot项目,我使用了一个名为jsoup的3rd party jar。

When I run the project from Eclipse, the code is working fine. 当我从Eclipse运行项目时,代码运行正常。 But when I use mvn clean package command and export it to an executable jar; 但是当我使用mvn clean package命令并将其导出到可执行jar时; project still works, but the parts that i use jsoup throws an exception that jsoup cannot be found. 项目仍然有效,但是我使用jsoup的部分引发了一个异常,即找不到jsoup。 So my executable jar does not contains jsoup. 因此,我的可执行jar不包含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, 这是我的pom文件,

<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> . 您正在使用JSoup 1.10.1版,但将其与<scope>system</scope> Maven doesn't include those jars in the artifacts build, just like <scope>provided</scope> . Maven不会在工件构建中包含这些jar,就像<scope>provided</scope> See also this Stackoverflow question and answers. 另请参阅 Stackoverflow问题和答案。

However JSoup is a normal jar like your other dependencies and is in Maven Central. 但是,JSoup和您的其他依赖项一样,是一个普通的jar,位于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. 这将使其包含在Spring Boot将为您创建的可执行jar中。 (And saves you from manually looking for that jar and updates etc.). (并且使您免于手动查找该jar和更新等)。

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. 如果您的第3方jar不支持Maven并且不在任何Maven存储库中,则可以从其下载该文件,并为其制作Maven工件,然后使用Maven部署插件将其部署到某些Maven存储库中。

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 请在以下位置查看它: 将第3方JAR部署到远程存储库的指南

that is a Maven command format from it: 这是Maven命令格式:

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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