Java 想法 intellij maven 项目无法实现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22956085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
idea intellij maven project can't make
提问by yazabara
I have maven project. Maven build complete SUCCESS. But i can't make this project.
我有 Maven 项目。Maven 构建完全成功。但我不能做这个项目。
[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:
聚甲醛:
<?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/iNaWO9gyhttp://screencast.com/t/iBGTyMpgH
你可以帮帮我吗?不幸的是,我无法添加截图.. 有截图:http: //screencast.com/t/iNaWO9gy http://screencast.com/t/iBGTyMpgH
Project settings - Libraries - empty;
项目设置 - 库 - 空;
reimport didn't help;
重新导入没有帮助;
采纳答案by zpontikas
Do the following steps:
执行以下步骤:
- Find your pom.xml in your files
- Right click on it --> Maven --> Import
- Wait for the project to load :D
- Press ctrl+alt+shift+s(This opens the Projects window.)
- Go to libraries and see if they are empty (they shouldnt)
- If they are post your full pom.xml please so I can see the problem
- If you still have a problem got to File --> Invalidate Caches /Restart
- Go to maven and Reimport All Maven Projects
- 在你的文件中找到你的 pom.xml
- 右键单击它 --> Maven --> 导入
- 等待项目加载:D
- 按ctrl+ alt+ shift+ s(这将打开“项目”窗口。)
- 去图书馆看看它们是否是空的(他们不应该)
- 如果他们发布了完整的 pom.xml,请让我看到问题
- 如果您仍然遇到问题,请转到文件 --> 使缓存无效/重新启动
- 转到 maven 并重新导入所有 Maven 项目
回答by Blekit
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.
选项Maven -> Reimport
应该强制 Intellij 重新加载所有依赖项。或者,如评论中所述,您可以单击视图中的Reimport All Maven Projects
按钮Maven Projects
。
回答by david99world
Open the module dependencies (press F12 on the module), go to Modules -> Dependencies
and make sure maven imports are part of the of this.
打开模块依赖项(在模块上按 F12),转到Modules -> Dependencies
并确保 maven 导入是其中的一部分。
回答by naXa
Try to import the project from sources, if this answerdidn't help you.
如果此答案对您没有帮助,请尝试从源中导入项目。
回答by datta
The following worked for me.
以下对我有用。
- Deleted the maven dependency from my local repository
- mvn clean install downloaded the dependency again
- File --> Invalidate Caches/Restart
- I still saw the compilation error
- on my mac, I hit option + enter, intellij asked me to add the jar to classpath
- build -> make project
- 从我的本地存储库中删除了 maven 依赖项
- mvn clean install 再次下载了依赖项
- 文件 --> 使缓存无效/重新启动
- 我还是看到编译错误
- 在我的 Mac 上,我点击了 option + enter,intellij 要求我将 jar 添加到类路径
- 构建 -> 制作项目
回答by Hamid
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
回答by swade
Right click on pom.xml
and click Add as Maven Project
右键单击pom.xml
并单击Add as Maven Project
回答by Lucas Amorim Silva
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:
就我而言,我有自己的 apache-maven-3.5.2 文件夹,配置错误导致了我的问题。也许这也是你的情况:
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.
匆忙中,我将本地存储库设置为 C:/my/folder/apache-maven-3.5.2/settings.xml,但它必须是一个文件夹,因此 Maven 不允许我下载依赖项。然后我更改了默认值(在图片中)并且它起作用了。