简体   繁体   English

即使在项目中检测到错误,eclipse 有没有办法运行 Java 程序?

[英]Is there a way for eclipse to run a Java program even if there are errors being detected in the project?

I have a project with multiple errors in my eclipse workspace.我的 eclipse 工作区中有一个项目有多个错误。 Is there a way to run eclipse and ignore these errors?有没有办法运行 eclipse 并忽略这些错误? I need to do this, since the project contains subprojects.我需要这样做,因为该项目包含子项目。 Some of these contain errors.其中一些包含错误。 I am only working on one of these.我只在其中之一上工作。 However, eclipse won't run the one working on because of the errors in the other project.但是,由于另一个项目中的错误,eclipse 不会运行正在处理的那个。

In Eclipse if you attempt to run an app that contains compile errors, you'll see the dialog "Errors exist in required project(s). Proceed with launch?"在 Eclipse 中,如果您尝试运行包含编译错误的应用程序,您将看到对话框“所需项目中存在错误。是否继续启动?”

If you select 'Proceed' Eclipse will attempt to execute the code.如果您选择“继续”,Eclipse 将尝试执行代码。 Depending where the errors are, you may be partially successful to execute at least some of the code.根据错误的位置,您可能至少部分成功地执行了一些代码。

This approach works if there is a compile error in a method that is not called from any other existing code.如果未从任何其他现有代码调用的方法中存在编译错误,则此方法有效。 The existing code will run and execute, and the compile error in a method that is not called doesn't impact the other code.现有代码将运行并执行,未调用方法中的编译错误不会影响其他代码。

I believe Eclipse is able to do this by how it incrementally compiles code.我相信 Eclipse 能够通过它如何增量编译代码来做到这一点。

Generally, no.一般来说,没有。 Those errors prevent the compiler from generating the output that is actually run.这些错误会阻止编译器生成实际运行的输出。

Depends on the type of error you have.取决于您遇到的错误类型。 Consider the following example:考虑以下示例:


public class CompileError {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
    
    private method() {
        
    }
}

The method is missing a return type and trying to run it will show a warning dialog.该方法缺少返回类型,尝试运行它会显示警告对话框。 But selecting "Proceed" will still run the example and print "Hello World".但是选择“继续”仍会运行示例并打印“Hello World”。

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

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