Eclipse 在调试时没有选择 Maven 附加的源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10569663/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:03:20  来源:igfitidea点击:

Eclipse not picking up Maven attached source on debug

eclipsemaven

提问by hajime

I've downloaded the source for all the Maven JARs in my buildpath using Maven->Download Sources and mvn eclipse:eclipse -DdownloadSources=true, which worked! When I open up the build path I can see that the sources JARs are attached for every JAR file.

我已经使用 Maven->Download Sources 和 下载了我的构建路径中所有 Maven JAR 的源代码mvn eclipse:eclipse -DdownloadSources=true,这奏效了!当我打开构建路径时,我可以看到每个 JAR 文件都附加了源 JAR。

But when I run the damn thing on Tomcat 6 I keep getting "Source not found" page with "Edit Source lookup path" button. But the source is already attached in the build path. What isn't this working?

但是,当我在 Tomcat 6 上运行该死的东西时,我不断收到带有“编辑源查找路径”按钮的“未找到源”页面。但是源已经附加在构建路径中。这不工作怎么办?

When I manually point it to the JAR file by clicking on the "Edit Source lookup path" button it works. And when I manually point it to the folder it does not work. Why isn't Eclipse or Tomcat picking up the attached source in the build path?

当我通过单击“编辑源查找路径”按钮手动将其指向 JAR 文件时,它会起作用。当我手动将它指向文件夹时,它不起作用。为什么 Eclipse 或 Tomcat 没有在构建路径中获取附加的源代码?

Note:I'm using apache-maven-3.0.4, apache-tomcat-6.0.16 and Eclipse Indigo Service Release 2.

注意:我使用的是 apache-maven-3.0.4、apache-tomcat-6.0.16 和 Eclipse Indigo Service Release 2。

采纳答案by ssasa

Although this bug had the most votes of all bugs @Sonatype, it hasn't been fixed.

尽管此错误在所有错误 @Sonatype 中的票数最高,但尚未修复。

However I have filled an enhancement request on Eclipse Bugzilla and if you agree this issue "Source not found" should be fixed, please vote for it here.

但是,我已经在 Eclipse Bugzilla 上填写了一个增强请求,如果您同意“找不到源”这个问题应该被修复,请在这里投票。

You can found three workarounds here.

您可以在此处找到三种解决方法。

回答by displayname

I found this com.ifedorenko.m2e.sourcelookupplugin. The link was provided in "Java Debugging: Source not found".

我找到了这个com.ifedorenko.m2e.sourcelookup插件。该链接在“ Java 调试:未找到源代码”中提供。

Go to Help > Install New Software ..and use

前往Help > Install New Software ..并使用

http://ifedorenko.github.com/m2e-extras/

http://ifedorenko.github.com/m2e-extras/

to search for the links. After installing this plugin I was finally able to debug the source code of dependencies.

搜索链接。安装这个插件后,我终于能够调试依赖项的源代码了。

回答by Henryk Paluch

Use ExternalMaven instead of default Embeddedin Debug Configurationsdialogue.

调试配置对话框中使用外部Maven 而不是默认嵌入

Please see example screenshot below (menu Run -> Debug Configurations...):

请参阅下面的示例屏幕截图(菜单运行 -> 调试配置...):

Configure external Maven

配置外部Maven

Tested environment:

测试环境:

  • Eclipse IDE for Java Developers: Oxygen.1a Release (4.7.1a), 64-bit (from spring.io)
  • Oracle JDK jdk1.8.0_144, 64-bit
  • Maven: 3.5.2
  • OS: Windows 10 Enterprise N, 64-bit
  • Test goal hpi:run(sample Jenkins plugin)
  • 面向 Java 开发人员的 Eclipse IDE:Oxygen.1a 版本 (4.7.1a),64 位(来自 spring.io)
  • Oracle JDK jdk1.8.0_144,64 位
  • Maven:3.5.2
  • 操作系统:Windows 10 Enterprise N,64 位
  • 测试目标hpi:run(示例 Jenkins 插件)

回答by luislobo

In my case the problem was related with the source code attached with the "Debug Configuration", maybe some remnants form a migration to Maven.

在我的情况下,问题与“调试配置”附带的源代码有关,也许一些残余物形成了到 Maven 的迁移。

I solved it by going to the "Debug Configurations..." page and selecting the configuration in case, then at the "Sources" tab I restored the defaults, which added all the project's Maven dependencies.

我通过转到“调试配置...”页面并选择配置来解决它,然后在“源”选项卡中我恢复了默认值,它添加了项目的所有 Maven 依赖项。

回答by winry

Window->Preferences->JBoss Tools->Source Lookup

Window->Preferences->JBoss Tools->Source Lookup

make sure you have check "Automatically add the JBoss Maven source container to all JBoss As launch configurations". and under "Automatically configure the Java Source Attachment", choose "Always".

确保您已选中“自动将 JBoss Maven 源容器添加到所有 JBoss 作为启动配置”。并在“自动配置 Java 源附件”下,选择“始终”。

this helps myself out of the problem.

这有助于我自己摆脱这个问题。

回答by cellepo

I think I fixed this for myself by updating my Eclipse m2e. I think I had version ~1.2, and then updated to latest [as of writing] 1.6.2.

我想我通过更新我的Eclipse m2e为自己解决了这个问题。我想我的版本是 ~1.2,然后更新到最新的 [撰写时] 1.6.2。

The Eclipse Bug commentshelped me figure this out.

Eclipse的错误意见帮我想出解决办法。

Now I can debug into my gquery-dnd-bundle-1.0.6!

现在我可以调试到我的 gquery-dnd-bundle-1.0.6!

回答by Amir

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${version.maven-source-plugin}</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                        <goal>test-jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

回答by Amir

The "target" maven project should emit it's source code before the "client" projects can have access to the source code. I solved the issue by using the maven-source-pluging in the "target" project: https://maven.apache.org/plugins/maven-source-plugin/index.html

“目标”maven 项目应该在“客户端”项目可以访问源代码之前发出它的源代码。我通过在“目标”项目中使用 maven-source-pluging 解决了这个问题:https://maven.apache.org/plugins/maven-source-plugin/index.html

Just use the following snippet in the pom.xml file of the target project, make a release, and use the release version into the pom.xml file of the client project. Then eclipse can automatically let you "jump" to the target project seamlesly:

只需在目标项目的 pom.xml 文件中使用以下代码片段,进行发布,并将发布版本使用到客户端项目的 pom.xml 文件中。然后eclipse可以自动让你无缝地“跳转”到目标项目:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${version.maven-source-plugin}</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                        <goal>test-jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>