我正在使用 Eclipse Kepler 和 Apache Maven 3.1.1。据我所知,我刚刚安装了两者并且安装正确。
我正在尝试从 Maven 存储库安装 Joda Time。我将依赖项添加到 pom.xml,但即使使用 Maven 全新安装,我的项目也无法解析 joda 库。
我的存储库位于 USER_FOLDER/.m2/repository/。在我导航到我的项目文件夹并运行“mvn clean”,然后“mvn install”之后,joda-time 文件夹及其内容就在那里。
我没有更改我的 Eclipse 项目中的任何构建路径或其他项目设置。
安装了 Eclipse Maven 集成。
我遵循了在 Spring 网站上找到的教程:http://spring.io/guides/gs/maven/
我的文件结构如下:
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]
这是我的 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>
这是我的 HelloWorld.java 主文件。在导入行上,我收到错误消息“导入 org.joda 无法解析”。
package main.java.hello;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
}
}
最佳答案
mvn eclipse:eclipse
还需要为 eclipse 生成包含 .classpath 的项目文件。
关于java - Eclipse 项目找不到 "org.joda",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21820078/