eclipse 调试时打开 .class 文件而不是 .java

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

.class file opens instead of .java while debugging

eclipse

提问by Alin

Current setup:

当前设置:

  • MainProjectwhich is a Library Project

  • BranchProjectwhich is a new projects and has MainProject as a Reference

  • MainProject是一个图书馆项目

  • BranchProject这是一个新项目,以 MainProject 作为参考

Whenever I debug and a file from MainProject is on focus (actually BranchProject has only graphic and xml layout changes) the Debug window opens a .class file which is read only. I want it to open the .java file so I can edit it directly.

每当我调试并且 MainProject 中的文件处于焦点时(实际上 BranchProject 只有图形和 xml 布局更改),调试窗口会打开一个只读的 .class 文件。我希望它打开 .java 文件,以便我可以直接编辑它。

回答by Steven

Skyler's answer from this post worked for me: Opening source code from debug view edits .class after Android R18 update

Skyler 在这篇文章中的回答对我 有用:Android R18 更新后从调试视图编辑 .class 打开源代码

Here is a summary: The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.

总结如下: 修复方法是在调试视图中右键单击项目名称,然后从菜单中选择“编辑源查找...”。从那里,删除默认查找路径。之后,手动添加您的项目引用的关联项目(不是 jars)。这是通过单击添加,选择 Java 项目,然后检查适当的项目来完成的。

回答by Graeme

When you're using a Library project one of the things you're in fact doing is compiling your Library project into a jar and then referencing that jar in your calling Project.

当您使用图书馆项目时,您实际上正在做的一件事是将您的图书馆项目编译成一个 jar,然后在您的调用项目中引用该 jar。

If you right click the Project, and select "Configure Build Path" you'll see a tab called "Libraries", if you look inside "Android Dependencies" you'll notice a list of jar's corresponding to your Library projects.

如果您右键单击项目,然后选择“配置构建路径”,您将看到一个名为“库”的选项卡,如果您查看“Android 依赖项”内部,您会注意到与您的库项目对应的 jar 列表。

These jars are expandable, showing you that they have a slot for a source attachment. Usually this would be editable allowing you to directly link the source but in terms of ADT these are already filled and are uneditable.

这些 jars 是可扩展的,向您展示它们有一个用于源附件的插槽。通常这将是可编辑的,允许您直接链接源,但就 ADT 而言,这些已填充且不可编辑。

When debugging these files you're linked to a read-only class file with this attached source. This is because you're not running against source files directly, you're running against a pre-compiled class file. Until the ADT team get this functionality in place, you're pretty much forced to jump to the direct source code and rebuild everything.

调试这些文件时,您将链接到带有此附加源的只读类文件。这是因为您不是直接针对源文件运行,而是针对预编译的类文件运行。在 ADT 团队获得此功能之前,您几乎被迫跳转到直接源代码并重新构建所有内容。

EDIT

编辑

See @Steven linked answer :)

请参阅@Steven 链接的答案:)

回答by Shivaramakrishna Agapu

I faced the same issue while debugging the a .javafile using Eclipse IDE. As per my understanding this issue comes when we put the xyz.classfile of xyz.javafile or JARat the project build path. Delete the .classor JARfile from the project class path and rerun .java file in the debug mode. This time you see a source not found window. Click on "Source not found" button and check "Find duplicates..." at the bottom of the window. Done your problem is solved :)

我在.java使用 Eclipse IDE调试文件时遇到了同样的问题。根据我的理解,当我们放置xyz.class文件xyz.java文件或JAR项目构建路径时,就会出现这个问题。从项目类路径中删除.classorJAR文件并在调试模式下重新运行 .java 文件。这次您会看到一个找不到源的窗口。单击“未找到源”按钮并选中窗口底部的“查找重复项...”。完成你的问题解决了:)

回答by ataraxis

The problem is that the class file is preferred over the java (by default), here is how you can change that for Eclipse (tested on NEON 2):

问题是类文件比 java 更受欢迎(默认情况下),这里是如何为 Eclipse 更改它(在 NEON 2 上测试):

  1. Right-click on the Projectin the Project-Explorer, click Properties
  2. On the new window select: Run/Debug Settings
  3. Create a new configuration(or duplicate another one)
  4. Select the new config and click Edit...
  5. Go to the tab Source
  6. Select the Defaultand Remove
  7. Create a new path with Add..., select Java Library, then JRE System Library
  8. Create a new path with Add..., select the location where the sourcecodeis by Workspace folder (if it is a project in the same workspace) or File System directory (it it is not)
  1. 右键单击项目资源管理器中的项目,单击属性
  2. 在新窗口中选择:运行/调试设置
  3. 创建一个新配置(或复制另一个)
  4. 选择新配置并单击编辑...
  5. 转到选项卡
  6. 选择默认删除
  7. 使用Add...创建一个新路径,选择Java Library,然后选择JRE System Library
  8. 使用Add...创建一个新路径,通过 Workspace 文件夹(如果它是同一工作区中的项目)或 File System 目录(不是)选择源代码所在的位置

回答by AntimoV

If you tried all above hints and it still doesn't work try this solution, it worked form me:

如果您尝试了上述所有提示但仍然无效,请尝试此解决方案,它对我有用:

  1. Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path...
  2. Select tab Order and Export
  3. select library that you can't reach code and then click on button Bottom
  4. Then click on Apply and Close
  1. 右键单击Package-Explorer中的Project,点击Build Path -> Configure Build Path...
  2. 选择选项卡订购和导出
  3. 选择您无法访问代码的库,然后单击按钮底部
  4. 然后点击应用并关闭

hope this can help you

希望这可以帮到你

回答by Simulant

I think this depends on, how you set up the dependency in eclipse. You should set up your BranchProject to depend on the source-Files of your MainProject. If you depend on compiles Class-Files is obvious that the debugger opens the class files, because it does not know about the source files.

我认为这取决于您如何在 Eclipse 中设置依赖项。您应该将 BranchProject 设置为依赖于 MainProject 的源文件。如果您依赖编译类文件,则很明显调试器会打开类文件,因为它不知道源文件。

回答by Seraphim's

I found a good solution for me here:

我在这里找到了一个很好的解决方案:

Using Android library in eclipse and jumping to class files instead of source file that is within eclipse workspace

在eclipse中使用Android库并跳转到类文件而不是eclipse工作区中的源文件

Simply, select each library project your project depends on, and use Top or Up to move it above the projects outputs. Eg. move all library projects to the top.

只需选择您的项目所依赖的每个库项目,然后使用 Top 或 Up 将其移动到项目输出上方。例如。将所有库项目移至顶部。

回答by Sergei

  1. Open main project properties -> Java Build Path -> Projectstab and add there projects the main project depend on.
  2. Switch to Order and Exporttab and uncheck Android Dependencies
  3. Enjoy
  1. 打开main project properties -> Java Build Path -> Projects选项卡并添加主项目所依赖的项目。
  2. 切换到Order and Export选项卡并取消选中Android Dependencies
  3. 享受