0

I'm writing assignment on coursera.org Java course. I'm using Maven and I have external jars that I have to use in this course (course requirements).

This is part of my 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. Below, following errors occur:

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

enter image description here

But I've successfully added the jar to maven:

enter image description here

What am I missing?

ducin
  • 25,621
  • 41
  • 157
  • 256
  • Restart eclipse or ctrl+f5 on the project? Try deleting the import then hovering over stdIn and see if it offers an import, maybe the directory is wrong? I honestly have no idea, just throwing some ideas out there. If I'm using external jars in eclipse I usually right click the project, goto build and 'add external jars'. Good luck! – brdu Feb 16 '14 at 10:32
  • What catches my eye is, that the `stdlib-1.0.jar` does not contain the package `org.coursera.etc`, but only the default package. Are you sure, that you are using the right jar-File? – qqilihq Feb 16 '14 at 10:34
  • @qqilihq I think you might be right. I cannot change the jar. Should I modify my maven settings (gropuId maybe)? – ducin Feb 16 '14 at 10:52
  • Modifying maven settings will not help. What the content of the JAR file under "default package"? Are you sure, that the JAR file is not corrupted? From which maven repository is the JAR imported? – qqilihq Feb 16 '14 at 10:57
  • Jar is provided by course authors. The just put a default package and students shall use it along with drJava and javac. I wanted to try maven and eclipse to do it. I think that I'm unable to do it nicely :/ I'm afraid it's the same as in http://stackoverflow.com/a/15124546/769384 – ducin Feb 16 '14 at 11:08
  • @tkoomzaaskz Agree, the problem is the default package. But have you seen this? http://introcs.cs.princeton.edu/java/stdlib/ (scroll down to Q+A, second entry). – qqilihq Feb 16 '14 at 11:30

2 Answers2

0

You need to do the following steps if you have a eclipse-maven plugin installed.

  1. Run the command 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.)
Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
0

1.create a folder src\lib and paste your jar file

2.your pom.xml should be like this.

 <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/