简体   繁体   English

在 spring 启动 maven 项目中与第三方 jar 的编译错误

[英]Compilation error with a 3 rd party jar in spring boot maven project

I have a spring boot project in Eclipse.我在 Eclipse 中有一个 spring 引导项目。 I have added an external 3rd party jar in project build path which is not a maven dependency.我在项目构建路径中添加了一个外部第 3 方 jar,它不是 maven 依赖项。 Now I am able to import 2 classes from the jar that I need and I wrote my some implementation.现在我可以从我需要的 jar 中导入 2 个类,并且我编写了一些实现。 Now when i am trying to build my maven project with clean install , I am getting compilation failure with the same 2 imports that I have used.现在,当我尝试使用全新clean install构建我的 maven 项目时,我使用与我使用的相同的 2 个导入来编译失败。 The error says: package does not exist.错误说:package 不存在。

Am I missing anything in the configuration part?我在配置部分遗漏了什么吗? I have added the jar as external jar in project build path.我在项目构建路径中添加了 jar 作为外部 jar。 Then I have clean compiled the project.然后我干净地编译了这个项目。 is there anything else that i need to do to use a 3 rd party jar in a spring boot project which is build by maven?在由 maven 构建的 spring 引导项目中使用第三方 jar 时,我还需要做些什么吗?

You must add this external jar as a dependency to make the maven build work.您必须将此外部 jar 添加为依赖项,以使 maven 构建工作。

There is a system scope for that purpose.为此目的,有一个系统 scope。 Example:例子:

<dependency>
  <groupId>javax.sql</groupId>
  <artifactId>jdbc-stdext</artifactId>
  <version>2.0</version>
  <scope>system</scope>
  <systemPath><path_to_jar>/your.jar</systemPath>
</dependency>

First add a local repo like below:首先添加一个本地仓库,如下所示:

    <repository>
        <id>in-project</id>
        <name>Local Project Repo</name>
        <url>file:///${project.basedir}/lib/</url>
    </repository>

Then add the dependency as below:然后添加如下依赖:

    <dependency>
        <groupId>abcd</groupId>
        <artifactId>efgh</artifactId>
        <version>1.X.O</version>
    </dependency>

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

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