java Intellij-idea无法查看生成的源目录

1hdlvixo  于 2023-06-20  发布在  Java
关注(0)|答案(3)|浏览(149)

我在IntelliJ中有一个maven项目,我通过执行Files>Project Structure并标记为source,将生成的sources目录标记为source。我也用另一种方法完成了它,右键单击文件夹并标记为generated-sources。
当我创建一个SOAP实现时,我仍然收到错误消息,说IntelliJ找不到这些文件夹Cannot resolve symbol 'name_of_folder'中的内容
有谁知道如何解决这个问题吗?从我可以看到我已经做了一切正确的标记,该文件夹和IntelliJ应该能够从那里读取

3qpi33ja

3qpi33ja1#

已修复此错误....
IntelliJ正在将我的generated-sources/cxf文件夹中的所有subdir标记为源根...因此,一个简单的突出显示所有文件夹和取消标记为来源解决了这个问题。

dzjeubhm

dzjeubhm2#

我也遇到过类似的情况,我必须通过pom.xml文件从脚本生成一个Java类。即使在编译包后我可以看到Java类成功生成,我也提到我无法导入生成的Java类并使用它。
由于这花了我很多时间来解决这个问题,我找不到任何适当的答案,我张贴的步骤,我执行,以便它可以帮助任何人在未来有类似的问题。
1.首先通过File -> ProjectStructure-> modules将生成的源目录标记为源。单击Source选项卡并将生成的文件夹添加为源。
1.右键单击generated source文件夹下的文件夹并选择markdirectory as -> Generated sources root
1.使用此插件,以便生成的类可以导入到任何其他类。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <id>add-java-source</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>${project.build.directory}/generated-sources/{folderUnderGeneratedSrcFolder} </source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>

希望这有帮助!!!!!

fivyi3re

fivyi3re3#

在Preferences > Build,Execution,Deployment > Gradle中取消选中“Create Separate module per source set”,然后重新构建/ gradle刷新

相关问题