문제

I have maven project. Maven build complete SUCCESS. But i can't make this project.

[INFO] BUILD SUCCESS

Project contains one module. Idea can't see dependencies.

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:

<?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

Project settings - Libraries - empty;

reimport didn't help;

도움이 되었습니까?

해결책

Do the following steps:

  1. Find your pom.xml in your files
  2. Right click on it --> Maven --> Import
  3. Wait for the project to load :D
  4. Press ctrl+alt+shift+s (This opens the Projects window.)
  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
  7. If you still have a problem got to File --> Invalidate Caches /Restart
  8. Go to maven and Reimport All Maven Projects

다른 팁

Option Maven -> Reimport should force Intellij to reload all dependencies. Alternatively, as mentioned in comments you can click the Reimport All Maven Projects button in Maven Projects view.

In my case, I had my own apache-maven-3.5.2 folder and a misconfiguration created my problem. 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. Then I changed the default (in the picture) and it worked.

enter image description here

Open the module dependencies (press F12 on the module), go to Modules -> Dependencies and make sure maven imports are part of the of this.

Try to import the project from sources, if this answer didn't help you.

The following worked for me.

  1. Deleted the maven dependency from my local repository
  2. mvn clean install downloaded the dependency again
  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
  6. 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

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.

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

Right click on pom.xml and click Add as Maven Project

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top