Eclipse/Maven 项目缺少必需的库/缺少工件

Eclipse / Maven Project is missing required library / Missing artifact

我在使用 Maven 的 Eclipse 中遇到如下错误:

Missing artifact org.eclipse:swt:jar:3.7.
Project 'davmail' is missing required library: '/home/buzz-dee/.m2/repository/org/eclipse/swt/3.7.0/swt-3.7.0.jar'

如上图所示,大多数库都已找到,但有些库未找到。但是文件在正确的位置。:

ls ~/.m2/repository/org/eclipse/swt/3.7.0/
swt-3.7.0.jar.lastUpdated  swt-3.7.0.pom.lastUpdated

这是部分 pom.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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>davmail</groupId>
    <artifactId>davmail</artifactId>
    <packaging>jar</packaging>
    <version>4.6.1</version>
    <name>DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange Gateway</name>
    <organization>
        <name>Mickaël Guessant</name>
    </organization>
    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>xwiki</id>
            <layout>default</layout>
            <url>http://maven.xwiki.org/externals</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-webdav</artifactId>
            <version>2.4.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.jackrabbit</groupId>
                    <artifactId>jackrabbit-jcr-commons</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.3</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse</groupId>
            <artifactId>swt</artifactId>
            <version>3.7.0</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.htmlcleaner</groupId>
            <artifactId>htmlcleaner</artifactId>
            <version>2.2</version>
        </dependency>
        <!-- included in Java 1.6, needed with Java 1.5 -->
        <dependency>
            <groupId>org.codehaus.woodstox</groupId>
            <artifactId>woodstox-core-asl</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.samba.jcifs</groupId>
            <artifactId>jcifs</artifactId>
            <version>1.3.14</version>
        </dependency>
        <dependency>
            <groupId>net.freeutils.charset</groupId>
            <artifactId>jcharset</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.boris.winrun4j</groupId>
            <artifactId>winrun4j</artifactId>
            <version>0.4.5</version>
        </dependency>
    </dependencies>
    <pluginRepositories>
        <pluginRepository>
            <id>apache.snapshots</id>
            <url>http://repository.apache.org/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <sourceDirectory>src/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.2</version>
            </plugin>
        </plugins>
    </build>
</project>

有什么问题吗?

忽略之前的回答。

Maven Central 没有 org.eclipse.swt 的版本 3.7.0。根据 Maven Central 的最新版本是 3.3.0。 You can see that in the link here. mvnrepository.com doesn't have it either.

您可以尝试使用 3.3.0 版本,或者您可以尝试手动添加到您的源文件夹中,但是,latest version available on their website is 4.4.2

根据this DavMail pageorg.eclipse:swt:jar:3.7.0是一个可选的依赖项。它不在 mavenCentral 中,您可能可以从其他存储库中找到它,但最简单的做法是从您的 pom 中删除该依赖项并使用 -U

进行重建

或者,如讨论的那样here, you can download the jar from here并使用安装命令将其安装到本地 .m2 存储库:

mvn install:install-file -DgroupId=org.eclipse -DartifactId=swt -Dversion=3.7.0 -Dpackaging=jar -Dfile=lib/swt-3.7-win32-x86.jar

不过请注意,这是一个临时修复,必须在您要构建此项目的每台机器上重复进行。这有点违背了将依赖管理卸载到像 Maven 这样的工具的目的。如果可行的话,我仍然希望从您的项目中删除 swt 作为依赖项。