java 复制源代码后,NetBeans 无法正确调试

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

NetBeans is not debugging correctly after I copy sources

javadebuggingnetbeansnetbeans6.8

提问by gotch4

Dunno why this happens... Ok here is the situation: I have a nb project on my laptop. I have the same project on my desktop. I copy the sources (not the entire project) on the desktop, overwriting the desktop sources. Everything cleans and builds ok. Then I start the debugger. On the main class I can debug step by step. If it goes into an internal method here is what happens:

不知道为什么会发生这种情况......好吧,情况是这样:我的笔记本电脑上有一个 nb 项目。我的桌面上有相同的项目。我在桌面上复制源(不是整个项目),覆盖桌面源。一切都清理干净,构建正常。然后我启动调试器。在主类上,我可以一步一步地调试。如果它进入内部方法,则会发生以下情况:

Listening on 37574
User program running
LineBreakpoint test.java : 45 successfully submitted.
Breakpoint hit at line 45 in class test by thread main.
Thread main stopped at test.java:45.
User program running
Not able to submit breakpoint LineBreakpoint baseControllerManager.java : 41, reason: No executable location available at line 41 in class baseClasses.JNW.baseControllerManager.
Invalid LineBreakpoint baseControllerManager.java : 41
Debugger stopped on uncompilable source code.
User program finished

As you can see until I'm in static method main it works (line 45) as I jump inside a non static method (that is an override) it comes out with that... I tried to:

正如您所看到的,直到我进入静态方法 main 它才起作用(第 45 行),因为我跳转到一个非静态方法(即覆盖)中时它会出现......我试图:

  • clean and build = no effect
  • manually delete build and dist = no effect
  • 清理和构建 = 没有效果
  • 手动删除 build 和 dist = 无效

What do you suggest?

你有什么建议?

For the sake of completeness I'm attaching the sources of the main class:

为了完整起见,我附上了主类的来源:

import baseClasses.JNW.baseAction;
import baseClasses.JNW.baseContResult;
import baseClasses.JNW.baseController;
import baseClasses.JNW.baseControllerManager;

public class test {

    public static class starter extends baseController {

        public static final String ACTION_START = "ACTION_START";

        @Override
        public baseContResult doAction(baseAction action) {

            if (ACTION_START.equals(action.action)) {
                manager.log("action start...");
                return new baseContResult(RESULT_OK, baseContResult.resultType.RESULT_OK);
            }
            return super.doAction(action);
        }

        @Override
        public void init() {
            super.init();
        }
    }

    public void startMe() {
        baseControllerManager manager;
        try {
            manager = new baseControllerManager();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        starter st = new starter();
        manager.setMainController(st);
        manager.doAction(new baseAction(starter.ACTION_START));
    }

    public static void main(String args[]) {


        test te = new test();
        te.startMe();

    }
}

回答by kdgregory

Look in the file nbproject/project.propertiesfor the property javac.debugand make sure that it's "true". If it is, grep for that property elsewhere in the nbproject directory and any local ant settings.

在文件中nbproject/project.properties查找该属性javac.debug并确保它是“true”。如果是,请在 nbproject 目录中的其他位置和任何本地 ant 设置中搜索该属性。

On a semi-related note: when I'm creating a project in NetBeans, even if the sources already exist elsewhere, I always create a new "Java Application", and let it populate the project directory as it wants. Then I can move in my sources and update the project, and NetBeans stays happy.

半相关说明:当我在 NetBeans 中创建项目时,即使源已经存在于其他地方,我总是创建一个新的“Java 应用程序”,并让它根据需要填充项目目录。然后我可以移入我的源代码并更新项目,NetBeans 就会保持满意。



Edit after you tried setting javac.debug:

尝试设置后编辑javac.debug

Looking at your question again, I see that you wereable to set a breakpoint on test.java, but not able to set one on baseControllerManager.java. That indicates to me that you're getting the latter class from a JAR somewhere, not from your project directory.

看着再次你的问题,我看你能设置一个断点test.java,但未能就组一个baseControllerManager.java。这向我表明您是从某个地方的 JAR 中获取后一个类,而不是从您的项目目录中获取。

So the first step is to make sure that you haven't defined a CLASSPATHenvironment variable. This is nevera good thing to do, regardless of whether you're using an IDE or a manual build.

所以第一步是确保你没有定义CLASSPATH环境变量。无论您是使用 IDE 还是手动构建,这都不是一件好事。

Next step is to look at the libraries that you've specified for the NetBeans project. You can use grepon a JARfile; the file directory is in plaintext. It should be sufficient to look for the unqualified classname.

下一步是查看您为 NetBeans 项目指定的库。您可以grep在 JARfile 上使用;文件目录是纯文本的。查找不合格的类名就足够了。

And the final thing is to verify that you are indeed compiling the class, by looking for it in the build directory.

最后一件事是通过在构建目录中查找它来验证您确实正在编译该类。

回答by gotch4

The property was not present in project.properties. So I added it (at a point where there where many javac.* properties...). Then I grepped like this:

该属性不存在于 project.properties 中。所以我添加了它(在那里有许多 javac.* 属性......)。然后我是这样的:

dario@dario-desktop:~/Scrivania/JNW$ grep -r javac.debug *
nbproject/project.properties:javac.debug=true
nbproject/build-impl.xml:        <property name="javac.debug" value="true"/>
nbproject/build-impl.xml:            <attribute default="${javac.debug}" name="debug"/>
nbproject/build-impl.xml:                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
nbproject/private/private.properties:javac.debug=true
nbproject/project.properties~:javac.debug=true

In fact it sees my addition on the last line.

事实上,它在最后一行看到了我的补充。

I cleaned and rebuilt the project. The debugger is not working again........... I think I'll kick my boss ass until he agrees to use eclipse or he fires me. I'll be unemployed but happy. Apart from joking, @kdgrgory, do you have any more ideas???

我清理并重建了项目。调试器不再工作了....... 我想我会踢我的老板直到他同意使用 eclipse 或者他解雇我。我会失业但很开心。除了开玩笑,@kdgrgory,你还有什么想法???

回答by Devon_C_Miller

Generally, an uncompilableerror means a symbol could not be resolved.

通常,不可编译的错误意味着无法解析符号。

If you have dependencies on other projects, libraries, or jars, make sure they have built successfully / are present.

如果您依赖于其他项目、库或 jar,请确保它们已成功构建/存在。

Checking "Build Projects on Classpath" (in project properties > Build > Compiling) will often fix this. If you don't have this checked, youare responsible for ensuring dependencies are already built.

检查“在类路径上构建项目”(在项目属性 > 构建 > 编译中)通常会解决这个问题。如果您没有选中此项,则有责任确保已经构建了依赖项。

回答by Daniel

I had the same problem and found that if I run clean from project tab it solves the problem.

我遇到了同样的问题,发现如果我从项目选项卡运行 clean 就可以解决问题。