Reputation: 173
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();
}
}
Upvotes: 5
Views: 9758
Reputation: 31
Right click the project and click on Configure> Convert Project to Maven Project
Upvotes: 3
Reputation: 278
Some things to try.
Are there any Maven errors whatsoever listed in the 'Markers' View? (Other than the missing import, of course). Frequently, a misspelled Maven configuration can be the cause of this problem.
If not, try one of the following:
Right-click the project and select Maven->Update Project.
Restart Eclipse.
Delete the errors, quit, and run "mvn clean compile" from the command line. Start Eclipse, right click your project, and "Refresh".
Delete the errors, quit, delete everything in your m2 repository, and run "mvn clean compile" from the command line. tart Eclipse, right click your project, and "Refresh"
Sacrifice 50 bulls to Lord Eclipse. Sometimes this is the only resort. I don't like it, but the alternative is to shell out bucks for Intellij.
Upvotes: 0
Reputation: 4123
mvn eclipse:eclipse
Is also required to generate project files which includes .classpath for eclipse.
Upvotes: 3