1

I wanted to import the following GitHub project to eclipse, and I did it like that. The problem is that I get many errors that look like this:

The import X cannot be rsolved

when X is some libaray (for example: javassist, com.google). I can solve some of those errors by adding relevant jar files, but there are errors which are more difficult to solve. Also, it doesn't seem like a good way for solving it anyway.
How can I import a project from GitHub to Eclipse without getting those errors?

John
  • 861
  • 1
  • 7
  • 19

2 Answers2

1

Try executing mvn eclipse:eclipse to create the .project and .classpath files for Eclipse. Then import the project via Eclipse. All required libraries should then be on the classpath.

Here's the resulting .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/4.12/junit-4.12.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/fasterxml/jackson/core/jackson-annotations/2.8.5/jackson-annotations-2.8.5.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/fasterxml/jackson/core/jackson-databind/2.8.5/jackson-databind-2.8.5.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/fasterxml/jackson/core/jackson-core/2.8.5/jackson-core-2.8.5.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/openjdk/jmh/jmh-core/1.17.3/jmh-core-1.17.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/net/sf/jopt-simple/jopt-simple/4.6/jopt-simple-4.6.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/openjdk/jmh/jmh-generator-annprocess/1.17.3/jmh-generator-annprocess-1.17.3.jar"/>
</classpath>

As you can see, Maven takes care of adding quite a few dependenices to your classpath.

Once the files are generated, I find the most convenient way to get Java projects that live within Git repositories into Eclipse to use this approach:

  • Open the Git Repositories View (Window → Show View → Other → Git → Git Repositories)
  • Select 'Add an existing local Git Repository to this view'
  • Select the location where you cloned the repository to locally
  • Right click the repository in the Git Repositories View and select 'Import Projects'
sebkur
  • 658
  • 2
  • 9
  • 18
  • https://stackoverflow.com/a/36242422/2970947 – Elliott Frisch Jan 06 '18 at 17:14
  • Yes, you're right the Maven eclipse plugin is retired, see official information here: http://maven.apache.org/plugins/maven-eclipse-plugin/ I guess in many projects it is still working as expected though. – sebkur Jan 06 '18 at 18:16
  • I used it for entirely too long myself, the new way is better; because you can edit the pom and update maven dependencies without regenerating the `.project` – Elliott Frisch Jan 06 '18 at 18:19
1

I just import this project without any erros. I'm using Eclipse EE (Oxygen Release 4.7.0). Here's what I did:

  • Checked out the code using git from command line, like the following: git clone https://github.com/json-iterator/java.git
  • Then, from Eclipse, Go to File -> Import... -> Maven -> Existing Maven Projects, and locate the folder named "java" and click "Finish".

That's it, wait a few seconds and the project will be imported.

diogenesgg
  • 2,601
  • 2
  • 20
  • 29