有没有办法让 Eclipse 在检测到项目中存在错误时仍然运行 Java 程序?

huangapple go评论58阅读模式
英文:

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

问题

我在我的 Eclipse 工作区中有一个项目,其中有多个错误。有没有办法运行 Eclipse 并忽略这些错误?我需要这样做,因为该项目包含子项目。其中一些包含错误。我只在其中一个子项目上进行工作。然而,由于其他项目中的错误,Eclipse 不会运行我正在处理的这个子项目。

英文:

I have a project with multiple errors in my eclipse workspace. Is there a way to run eclipse and ignore these errors? 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.

答案1

得分: 2

在Eclipse中,如果您尝试运行包含编译错误的应用程序,您将看到对话框“在所需项目中存在错误。是否继续启动?”

如果您选择“继续”,Eclipse将尝试执行代码。根据错误的位置,您可能部分成功地执行至少一些代码。

如果存在一个方法中的编译错误,而该方法未从任何其他现有代码中调用,那么这种方法会有效。现有的代码将运行和执行,而未被调用的方法中的编译错误不会影响其他代码。

我认为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?"

If you select 'Proceed' Eclipse will attempt to execute the code. 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.

答案2

得分: 1

通常不会。这些错误会阻止编译器生成实际运行的输出。

英文:

Generally, no. Those errors prevent the compiler from generating the output that is actually run.

答案3

得分: 1

取决于您遇到的错误类型。考虑以下示例:

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

    private method() {

    }
}

该方法缺少返回类型,并尝试运行它将显示一个警告对话框。但选择 "继续" 仍将运行示例并打印 "Hello World"。

英文:

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".

huangapple
  • 本文由 发表于 2020年10月2日 00:04:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/64159136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定