How to resolve import in Eclipse?

eocron :

Im new in Java development and not familiar with various kinds of import (Maven, Git, etc), so I make it simple:

import com.google.common.collect.*;
import com.google.gson.*;

These two is not resolved in code Im inspecting, and I have no idea what kind of actions I should take neither what I should import to resolve it but it is probably some popular library.

Is there complete guide how developers import packages in eclipse (for example C# developers use Nuget, despite there is a ton of hand made ones), or they really use all this enormous import selector?

Vishwa Ratna :

First of all Mavenise your current project and add the following dependency to it:

Goto: POM.XML after converting your current project to Maven project.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <groupId>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <version>1.0-SNAPSHOT</version>

      <properties>
       ------Properties Here----
      </properties>

      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>

        </dependency> 

          <dependency>
        <groupId>com.google.collections</groupId>
        <artifactId>google-collections</artifactId>
        <version>1.0-rc2</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>
--------Add your Dependencies here, remember you have to add dependencies under <dependencies> here </dependencies> ----------
      </dependencies>
    </project>

Search for all dependencies here: https://mvnrepository.com/ , incase you need more dependencies to import.

How to mavenise your current Java Project:

In your eclipse just right click on Java Project and click Configure and you should see “ Convert to Maven Project ” option.

What is POM.XML

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Now, you can add a dependency in pom.xml.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77029&siteId=1