简体   繁体   English

缺少Maven依赖关系,无法导入类

[英]Missing Maven Dependency and can not import class

I have created a new maven project by choosing org.apache.maven.archtypes maven.archtype.webapp . 我通过选择org.apache.maven.archtypes maven.archtype.webapp创建了一个新的maven项目。

I perform the below commands: 我执行以下命令:

  • right click pom > maven clean 右键单击pom> maven clean
  • right click pom > maven install. 右键单击pom> maven安装。
  • check maven user setting file 检查Maven用户设置文件
  • right click on project > maven update. 右键单击项目> Maven更新。

but maven dependency library is not added into libraries folder although a build success message has been output. 但是,尽管已输出构建成功消息,但Maven依赖库未添加到库文件夹中。

[INFO] Scanning for projects...
<p> 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO] BUILD SUCCESS
[INFO] Total time: 2.248 s
[INFO] Finished at: 2018-06-07T09:40:57+03:00
[INFO] Final Memory: 8M/20M

Here's my pom file, eg dependency mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype- 这是我的pom文件,例如,依赖项mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-

<?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.0http://maven.apache. rg/xsd/maven-4.0.0.xsd">

    <groupId>test</groupId>
    <artifactId>maven.test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>maven.test Maven Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.9.5</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

Here's my library screenshot without maven dependency 这是我的没有maven依赖的库截图

没有Maven依赖的库

As Amer mentioned , do a maven update for your project, if it doest work the try with different network(either use mobile phone network or home network) to update project then 如Amer所述,请为您的项目进行Maven更新,如果它无法在其他网络(使用手机网络或家庭网络)上进行尝试,则无法更新项目,然后
do a eclipse clean(not maven clean) for that project then do a 为该项目进行月食清洁(不是Maven清洁),然后执行
maven install . maven install
sometimes network block the jar file to download 有时网络会阻止jar文件下载

右键单击项目-> Maven->更新项目

I saw screen shot you attached but there is not any folder called "Maven Dependencies". 我看到了您连接的屏幕快照,但是没有任何名为“ Maven Dependencies”的文件夹。 So please try one option it may solve your problem...right click on project -> configure -> convert to maven. 因此,请尝试一种可能会解决您问题的选项...右键单击项目->配置->转换为Maven。

go to the source folder of the project using cmd and run maven command: mvn clean install ( this command won't work unless you specified path to maven/bin folder in path of system variables ) be sure you're not beyond the proxy, if you are, then you should configure maven to work with it. 使用cmd转到项目的源文件夹并运行maven命令:mvn clean install( 除非您在系统变量的路径中指定了maven / bin文件夹的路径,否则该命令将不起作用),请确保您没有超出代理的范围,如果是这样,则应配置Maven以使用它。 Link to how to configure a proxy in maven 链接到如何在Maven中配置代理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM