简体   繁体   English

在eclipse中导入外部jar

[英]importing external jar inside eclipse

I'm writing assignment on coursera.org Java course. 我正在Coursera.org Java课程上写作业。 I'm using Maven and I have external jars that I have to use in this course (course requirements). 我正在使用Maven,并且在此课程中必须使用外部jar(课程要求)。

This is part of my pom.xml: 这是我的pom.xml的一部分:

<dependency>
  <groupId>org.coursera.algs4part1</groupId>
  <artifactId>stdlib</artifactId>
  <version>1.0</version>
</dependency>

I can't make java compiler import the external jar file. 我无法使Java编译器导入外部jar文件。 Below, following errors occur: 下面,发生以下错误:

The import org.coursera.algs4part1.stdlib cannot be resolved

在此处输入图片说明

But I've successfully added the jar to maven: 但是我已经成功地将罐子添加到了Maven中:

在此处输入图片说明

What am I missing? 我想念什么?

You need to do the following steps if you have a eclipse-maven plugin installed. 如果安装了eclipse-maven插件,则需要执行以下步骤。

  1. Run the command mvn eclipse:eclipse 运行命令mvn eclipse:eclipse
  2. Go to Project Properties > Build Path > Libraries tab > Add Variable... button > Configure Variables... button > New button. 转到项目属性 > 构建路径 > 选项卡> 添加变量...按钮> 配置变量...按钮> 新建按钮。 Enter the variable name as M2_REPO and its value/path to the Maven Repository path (Usually it's like C:\\Users\\<username>\\.m2\\repository .) 输入变量名称M2_REPO及其值/ Maven存储库路径的路径(通常类似于C:\\Users\\<username>\\.m2\\repository 。)

1.create a folder src\\lib and paste your jar file 1.创建一个文件夹src \\ lib并粘贴您的jar文件

2.your pom.xml should be like this. 2.您的pom.xml应该是这样的。

 <groupId>org.coursera.algs4part1</groupId>
     <artifactId>stdlib</artifactId>
     <scope>system</scope>
     <version>1.0</version>
     <systemPath>${basedir}\src\lib\stdlib.jar</systemPath>
  </dependency>

Hopefully this will solve your problem and for more details visit http://noexceptionfound.blogspot.in/ 希望这可以解决您的问题,有关更多详细信息,请访问http://noexceptionfound.blogspot.in/

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

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