Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse project can't find "org.joda"

I'm using Eclipse Kepler, and Apache Maven 3.1.1. I just installed both and did so properly as far as I know.

I'm trying to install Joda Time from the Maven repository. I added the dependencies to the pom.xml, but my project can't resolve the joda libraries even with a maven clean install.

My repository is located at USER_FOLDER/.m2/repository/. The joda-time folder and its contents are present there after I navigate to my project folder in a prompt and run "mvn clean", then "mvn install".

I haven't changed any build paths or other project settings in my Eclipse project.

Eclipse Maven integration is installed.

I followed this tutorial found on the Spring website: http://spring.io/guides/gs/maven/

My file structure is as follows:

USER
|____ .m2
|    |____ repository
|         |____ joda-time [and other folders such as org]
|              |____ joda-time
|                   |____ 2.3
|                        |____ _remote.repositories
|                        |____ joda-time-2.3.jar
|                        |____ joda-time-2.3.jar.sha1
|                        |____ joda-time-2.3.pom
|                        |____ joda-time-2.3.pom.sha1
|____ workspace
|    |____ hello
|    |    |____ [project files]
|    |    |____ pom.xml
|    |    |____ dependency-reduced-pom.xml
|    |    |____ target
|    |         |____ [compiled files. Nothing related to Joda, though]
|    |____ .metadata [with .plugins folder and others]

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<dependencies>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>main.java.hello.HelloWorld</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

Here is my HelloWorld.java main file. On the import line, I get the error message "The import org.joda cannot be resolved".

package main.java.hello;

import org.joda.time.LocalTime;

public class HelloWorld {
    public static void main(String[] args) {
        LocalTime currentTime = new LocalTime();
    }
}
like image 463
John Douglas George Avatar asked Oct 01 '22 13:10

John Douglas George


2 Answers

mvn eclipse:eclipse

Is also required to generate project files which includes .classpath for eclipse.

like image 150
Himanshu Bhardwaj Avatar answered Oct 21 '22 07:10

Himanshu Bhardwaj


Right click the project and click on Configure> Convert Project to Maven Project

like image 3
AHMEDE Avatar answered Oct 21 '22 07:10

AHMEDE