简体   繁体   English

Eclipse 工程嵌套时搜索打开Java 没有语法高亮和源代码链接的文件?

[英]Eclipse search opens up Java file that has no syntax highlight or source code link when the project is nested?

Situation::情况::

  • Trying to search and open up a Java file.尝试搜索并打开 Java 文件。 In a nest project.在嵌套项目中。

搜巢项目 从 Eclipse 获取文件

  • And so, we have the file here, these 2 files the exactly same file,所以,我们这里有文件,这两个文件是完全相同的文件,

    • but, when the project is nested inside, Eclipse search opens up the file that has no syntax highlight or source code link (ie: unable to ctrl click on the code).但是,当项目嵌套在里面时,Eclipse 搜索打开没有语法高亮或源代码链接的文件(即:无法按住 ctrl 单击代码)。

      (ie: Eclipse opens up the Java file as if the Java file is not on a build path) (即:Eclipse 打开 Java 文件,就好像 Java 文件不在构建路径上一样)

      (though, if I search directly on that nested project, instead of on the parent project, then things are fine) (不过,如果我直接在那个嵌套项目上搜索,而不是在父项目上搜索,那么一切都很好)

    • I have to manually open up the file in the Project Explorer, to get the file with syntax highlight or source code link.我必须在 Project Explorer 中手动打开文件,以获取带有语法高亮显示或源代码链接的文件。

Ask::问::

  • How can I let Eclipse directly open up the Java file with syntax highlight (when I search on the parent project)如何让 Eclipse直接打开带有语法高亮的 Java 文件(当我在父项目上搜索时)

    (so that I dont need to manually search & click all the way through)? (这样我就不需要手动搜索并一直点击)?

You seems to be using Maven and you probably imported your project in Eclipse as Maven project.您似乎正在使用 Maven,并且您可能将 Eclipse 中的项目导入为 Maven 项目。

The problem with Maven and Eclipse is that usually Maven project are split as project aggregator (a pom.xml with only <module> ) which m2e will import: such aggregator project use a directory hierarchy. Maven 和 Eclipse 的问题是通常 Maven 项目被拆分为项目聚合器(一个pom.xml只有<module> ),m2e 将导入:这样的聚合器项目使用目录层次结构。

Eclipse, on the other hand, does not scan files as file system file, but as project related file: that's the main reason for your duplicate.另一方面,Eclipse 不将文件扫描为文件系统文件,而是扫描为项目相关文件:这是重复的主要原因。 The child project being contained in its parent, the same file is shown twice because for Eclipse, these are two distinct path.子项目包含在其父项目中,同一个文件显示两次,因为对于 Eclipse,这是两个不同的路径。

And since for the parent project, the file is simply a regular file it does not offer anything beside syntax highlighting.因为对于父项目,该文件只是一个普通文件,它除了语法高亮之外不提供任何东西。

You can:你可以:

  • close each aggregator project one by one;一个一个地关闭每个聚合器项目; for Eclipse, there are no really useful anyway.对于Eclipse,反正也没什么用。
  • don't import them (and I wish m2e-core would suggest it).不要导入它们(我希望 m2e-core 会建议它)。

You could also create a bug or vote for this one which seems related: https://bugs.eclipse.org/bugs/show_bug.cgi?id=533440您还可以创建一个错误或为此似乎相关的投票: https://bugs.eclipse.org/bugs/show_bug.cgi?id=533440

Note that this also affect other screen such as Show Resources (which is the subject of bug 533440).请注意,这也会影响其他屏幕,例如显示资源(这是错误 533440 的主题)。

The workaround I am using::我正在使用的解决方法::

workaround 01解决方法 01

Find the files in the nest projects as I did before, then get the class name, then ctrl shift t to search that class again.和之前一样在nest projects中找到文件,然后得到class这个名字,然后ctrl shift t再次搜索那个class。

  • Cons:缺点:
    • You have to manually copy and search the class name.您必须手动复制并搜索 class 名称。
    • There are possible other classes with same name (and you have to tell which one you want to go to).可能还有其他具有相同名称的类(您必须告诉 go 到哪个类)。
    • You will not be able to jump to the desire line.你将无法跳到欲望线。

workaround 02解决方法 02

Just search in the whole workspace .只需在整个workspace中搜索即可。 And directly open in the file in the child-project (ignore the results from parent-project).并直接在子项目中的文件中打开(忽略父项目的结果)。

  • Cons:缺点:
    • Time consuming when search the whole workspace (though, you can terminate it when you get the desire files, hopefully no missing results when you do that).搜索整个工作区时非常耗时(不过,您可以在获得所需文件时终止它,希望这样做时不会丢失结果)。
    • There are a lot duplicate / unnecessary results.有很多重复/不必要的结果。
    • You may not want to search the whole workspace.您可能不想搜索整个工作区。

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

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