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

发布于 2024-08-18 02:11:37 字数 2119 浏览 4 评论 0原文

不知道为什么会发生这种情况...好吧,情况是这样的:我的笔记本电脑上有一个 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

正如你所看到的,直到我进入静态方法 main 时,它才起作用(第 45 行),因为我跳转到一个非静态方法(即重写)中,它随之而来。 ..我尝试:

  • clean 和 build = 无效果
  • 手动删除 build 和 dist = 无效果

你有什么建议?

为了完整起见,我附加了主类的源代码:

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();

    }
}

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:

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:

  • clean and build = no effect
  • manually delete build and dist = no effect

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();

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城°AllureLove 2024-08-25 02:11:37

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

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


在尝试设置 javac.debug 后进行编辑:

再次查看您的问题,我发现您能够test.java 上设置断点,但无法在 baseControllerManager.java 上设置。这对我来说表明您是从某个 JAR 中获取后一个类,而不是从您的项目目录中获取。

因此,第一步是确保您尚未定义 CLASSPATH 环境变量。无论您使用的是 IDE 还是手动构建,这永远都不是一件好事。

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

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

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

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.


Edit after you tried setting javac.debug:

Looking at your question again, I see that you were able 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.

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

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

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

大姐,你呐 2024-08-25 02:11:37

一般来说,无法编译错误意味着无法解析符号。

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

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

Generally, an uncompilable error 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.

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

骑趴 2024-08-25 02:11:37

该属性不存在于project.properties 中。所以我添加了它(在有很多 javac.* 属性的地方......)。然后我像这样 grep:

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

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

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

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:

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???

胡渣熟男 2024-08-25 02:11:37

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文