【问题标题】:Eclipse / Maven Project is missing required library / Missing artifactEclipse/Maven 项目缺少必需的库/缺少工件
【发布时间】:2015-04-30 21:18:28
【问题描述】:

我在使用 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>

可能出了什么问题?

【问题讨论】:

  • .lastupdated 文件不是真正的工件。它最后一次在那个时间戳寻找它们,但没有找到它们。文件大小应该是赠品。见:stackoverflow.com/questions/2529218/…
  • 谢谢,我忽略了文件名swt-3.7.0.jar.lastUpdated 中的.lastUpdated。我在项目 libs 文件夹中已经有了这些文件。 Maven 命令是否也将该文件复制到 Maven 存储库文件夹?
  • 如果您连接到互联网,只需运行带有 -U 标志的 maven,它会强制下载依赖项。
  • 我运行了mvn -U clean compile install,但随后出现错误:[ERROR] Failed to execute goal on project davmail: Could not resolve dependencies for project davmail:davmail:jar:4.6.1: Could not find artifact org.eclipse:swt:jar:3.7.0 in central (http://repo1.maven.org/maven2) -&gt; [Help 1]
  • 正如下面的人指出的那样,swt:3.7 在 maven Central 中不可用。您使用的 davmail 版本似乎设置了错误的依赖项。我想是时候为你的 pom 添加更多排除项了。显然更多的人对 davmail 传递依赖有问题:sourceforge.net/p/davmail/mailman/davmail-users/thread/…

标签: java eclipse maven eclipse-luna


【解决方案1】:

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

或者,正如 here 所讨论的,您可以从 here 下载 jar 并使用 install 命令将其安装到本地 .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 作为依赖项从您的项目中删除。

【讨论】:

  • SWT jars 已经在签出的源代码中。无需再次下载。
【解决方案2】:

忽略之前的回答。

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

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

【讨论】:

  • 如果我删除了文件swt-3.7.0.jar.lastUpdatedswt-3.7.0.pom.lastUpdated,我会恢复它们,如果我点击“更新项目”。对于其他文件,我手动复制到该文件夹​​并单击正在工作的“更新项目”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-07
  • 2011-05-14
  • 2012-10-22
  • 2014-01-04
  • 2013-07-12
相关资源
最近更新 更多