IntelliJ和Maven Source文件夹问题

时间:2023-01-14 09:17:20

I'm trying to create a simple Java webapp using IntelliJ (v11.1.3) and integrate it with a simple maven pom file to download the Vaadin jar.

我正在尝试使用IntelliJ(v11.1.3)创建一个简单的Java webapp,并将其与一个简单的maven pom文件集成以下载Vaadin jar。

Here is my pom file:

这是我的pom文件:

<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>com.a.maven.project</groupId>
<artifactId>MavenProject</artifactId>
<version>0.1</version>
<packaging>war</packaging>

<dependencies>
<dependency>
  <groupId>com.vaadin</groupId>
    <artifactId>vaadin</artifactId>
  <version>6.8.2</version>
</dependency>

</project>

I am checking this project out from version control in order to set it up in IntelliJ. However, IntelliJ does not seem to be able to recognize that the "src" folder is the sources folder. I can manually set this to the sources folder in the project settings, which is a minor annoyance, but not a big deal. However, EVERY time i make a change to the pom file, IntelliJ "forgets" that this is the sources folder, and then all my Java files get red circles around them. Does anyone have any idea as to what could be causing this? I've tried just about everything to fix this, including specifying the source folder in my pom file, but nothing seems to work.

我正在从版本控制中检查此项目,以便在IntelliJ中进行设置。但是,IntelliJ似乎无法识别“src”文件夹是sources文件夹。我可以手动将它设置为项目设置中的sources文件夹,这是一个小麻烦,但不是什么大不了的事。但是,每次我对pom文件进行更改时,IntelliJ“忘记”这是sources文件夹,然后我的所有Java文件都会在它们周围出现红圈。有没有人知道造成这种情况的原因是什么?我已经尝试了解决这个问题的一切,包括在我的pom文件中指定源文件夹,但似乎没有任何工作。

Thanks in advance,

提前致谢,

Eric

埃里克

3 个解决方案

#1


14  

IntelliJ IDEA follows Maven conventions and will automatically configure /src/main/java as Sources root.

IntelliJ IDEA遵循Maven约定,并自动将/ src / main / java配置为Sources root。

In case you are using non-standard directories for the sources, check IDEA Maven FAQ for the workaround:

如果您使用非标准目录作为源,请检查IDEA Maven常见问题解答以获取解决方法:

<sourceDirectory>...</sourceDirectory> will be added as Source folder

#2


6  

It happened to me on Idea 11 that everything was ok, but sources were not recognized. I opened that project as maven - from parrent pom - and selected delete existing idea files and generate new. It worked then.

在Idea 11上我发现一切都很好,但是消息来源没有得到认可。我打开那个项目作为maven - 来自parrent pom - 并选择删除现有的想法文件并生成新的。它起作用了。

#3


1  

If you are not able to make java dir -> 'src/main/java' as your source root:

如果您无法将java目录 - >'src / main / java'作为源根目录:

  • create a new folder "java1" inside src/main
  • 在src / main中创建一个新文件夹“java1”
  • move all the folders and files inside java folder to java1
  • 将java文件夹中的所有文件夹和文件移动到java1
  • right click on java1 > mark directory as > source root
  • 右键单击java1>标记目录为> source root
  • delete java folder
  • 删除java文件夹
  • rename java1 -> java
  • 重命名java1 - > java

#1


14  

IntelliJ IDEA follows Maven conventions and will automatically configure /src/main/java as Sources root.

IntelliJ IDEA遵循Maven约定,并自动将/ src / main / java配置为Sources root。

In case you are using non-standard directories for the sources, check IDEA Maven FAQ for the workaround:

如果您使用非标准目录作为源,请检查IDEA Maven常见问题解答以获取解决方法:

<sourceDirectory>...</sourceDirectory> will be added as Source folder

#2


6  

It happened to me on Idea 11 that everything was ok, but sources were not recognized. I opened that project as maven - from parrent pom - and selected delete existing idea files and generate new. It worked then.

在Idea 11上我发现一切都很好,但是消息来源没有得到认可。我打开那个项目作为maven - 来自parrent pom - 并选择删除现有的想法文件并生成新的。它起作用了。

#3


1  

If you are not able to make java dir -> 'src/main/java' as your source root:

如果您无法将java目录 - >'src / main / java'作为源根目录:

  • create a new folder "java1" inside src/main
  • 在src / main中创建一个新文件夹“java1”
  • move all the folders and files inside java folder to java1
  • 将java文件夹中的所有文件夹和文件移动到java1
  • right click on java1 > mark directory as > source root
  • 右键单击java1>标记目录为> source root
  • delete java folder
  • 删除java文件夹
  • rename java1 -> java
  • 重命名java1 - > java