简体   繁体   English

想法intellij maven项目无法做到

[英]idea intellij maven project can't make

I have maven project. 我有maven项目。 Maven build complete SUCCESS. Maven构建完整的SUCCESS。 But i can't make this project. 但我不能做这个项目。

[INFO] BUILD SUCCESS [信息]建立成功

Project contains one module. 项目包含一个模块。 Idea can't see dependencies. Idea无法看到依赖关系。

Error:(3, 38) java: D:\Dropbox\Programming\java\spring\springBook\src\main\java\ch14\validator\ContactTestValidator.java:3: 
package org.springframework.stereotype does not exist

POM: POM:

<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springBook</groupId>
<artifactId>springBook</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Shared version number properties -->
<properties>
    <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
</properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <!--для валидации бинов необходима-->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <!--Spring Data JPA использует его - добавим и пользуемся-->
        <!--API для работы с датами-->
        <!--ch14 validator-->
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <!--ch14 validator-->
        <!--API интерфейса JSR-303-->
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <!--ch14 validator-->
        <!--API, которая поддерживает интерфейс JSR-303 - BeanValidation-->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.2.GA</version>
    </dependency>
    <dependency>
        <!--для валидации. (@Type...)-->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.6.2</version>
    </dependency>
    <!--Spring framework-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
</dependencies>
<build>
    <finalName>springBook</finalName>
</build>
</project>

Could you help me? 你可以帮帮我吗? Unfortunately, I can't add screenshots.. There are screenshots: http://screencast.com/t/iNaWO9gy http://screencast.com/t/iBGTyMpgH 不幸的是,我无法添加截图..有截图: http//screencast.com/t/iNaWO9gy http://screencast.com/t/iBGTyMpgH

Project settings - Libraries - empty; 项目设置 - 图书馆 - 空;

reimport didn't help; 重新进口没有帮助;

Do the following steps: 执行以下步骤:

  1. Find your pom.xml in your files 在文件中找到您的pom.xml
  2. Right click on it --> Maven --> Import 右键单击它 - > Maven - > Import
  3. Wait for the project to load :D 等待项目加载:D
  4. Press ctrl + alt + shift + s (This opens the Projects window.) ctrl + alt + shift + s (这将打开“项目”窗口。)
  5. Go to libraries and see if they are empty (they shouldnt) 去图书馆,看看它们是否为空(它们不应该)
  6. If they are post your full pom.xml please so I can see the problem 如果他们发布了你的完整pom.xml,那么我可以看到问题所在
  7. If you still have a problem got to File --> Invalidate Caches /Restart 如果你仍然有问题到文件 - >无效缓存/重新启动
  8. Go to maven and Reimport All Maven Projects 转到maven和Reimport All Maven项目

Option Maven -> Reimport should force Intellij to reload all dependencies. 选项Maven -> Reimport应强制Intellij重新加载所有依赖项。 Alternatively, as mentioned in comments you can click the Reimport All Maven Projects button in Maven Projects view. 或者,如评论中所述,您可以单击Maven Projects视图中的Reimport All Maven Projects按钮。

In my case, I had my own apache-maven-3.5.2 folder and a misconfiguration created my problem. 在我的情况下,我有自己的apache-maven-3.5.2文件夹,错误配置造成了我的问题。 Maybe it's your case too: 也许这也是你的情况:

In rush, I set the local repository to C:/my/folder/apache-maven-3.5.2/settings.xml, but it must be a folder so Maven didn't allow me to download the dependencies. 急,我将本地存储库设置为C:/my/folder/apache-maven-3.5.2/settings.xml,但它必须是一个文件夹,因此Maven不允许我下载依赖项。 Then I changed the default (in the picture) and it worked. 然后我改变了默认值(在图片中)并且它有效。

在此输入图像描述

打开模块依赖项(按模块上的F12),转到Modules -> Dependencies ,并确保maven导入是其中的一部分。

如果此答案对您没有帮助,请尝试从源中导入项目。

The following worked for me. 以下对我有用。

  1. Deleted the maven dependency from my local repository 从我的本地存储库中删除了maven依赖项
  2. mvn clean install downloaded the dependency again mvn clean install再次下载了依赖项
  3. File --> Invalidate Caches/Restart 文件 - >使高速缓存/重新启动无效
  4. I still saw the compilation error 我仍然看到编译错误
  5. on my mac, I hit option + enter, intellij asked me to add the jar to classpath 在我的Mac上,我点击选项+输入,intellij让我把jar添加到classpath
  6. build -> make project build - > make project

I had faced the same problem, and the issue was small. 我遇到了同样的问题,问题很小。 I had changed the location of settings.xml file of maven and Intellij was picking up the default from C:\\users\\.m2\\settings.xml 我更改了maven的settings.xml文件的位置,Intellij从C:\\ users \\ .m2 \\ settings.xml中获取了默认值

So point your maven settings.xml to the correct file as below: File--> Settings--> Build, Execution, Deployment--> Maven then on the right window, override "User settings file" to the settings.xml where you have in your local disk. 所以将maven settings.xml指向正确的文件,如下所示:文件 - >设置 - >构建,执行,部署 - > Maven然后在右侧窗口,将“用户设置文件”覆盖到您在的settings.xml中拥有本地磁盘。

If you have installed maven in a non-default location then this file you can find in: \\apache-maven-3.2.3\\conf\\settings.xml 如果您已在非默认位置安装了maven,则可以在以下位置找到此文件:\\ apache-maven-3.2.3 \\ conf \\ settings.xml

右键单击pom.xml ,然后单击Add as Maven Project

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

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