IntelliJ。调试程序,即使它没有编译

发布于 2024-12-04 16:52:49 字数 402 浏览 0 评论 0原文

我在IntelliJ中有一个Java项目可以编译,现在我正在慢慢改变。

有没有办法让 IntelliJ 运行项目,即使代码的某些部分仍然无法编译?如果是这样,怎么办?

你问为什么我需要这个?看这张票: IDEA-61945 运行和调试命令应忽略与正在运行的主程序无关的编译错误。 http://youtrack.jetbrains.net/issue/IDEA-61945?query=it# tab=Comments

请不要回答这篇文章询问我是否应该或不需要运行一个项目,即使它不能编译。请。

如果在IntelliJ中不可能,那么在maven中可以吗?如何?

I have a Java project in IntelliJ that compiles, and now I am slowly changing.

Is there a way to ask IntelliJ to run the project, even if some parts of the code still do not compile? If so, how?

Why I would need this, you ask? see this ticket:
IDEA-61945 Run and Debug commands should ignore compile errors not related to the main being run.
http://youtrack.jetbrains.net/issue/IDEA-61945?query=it#tab=Comments

Please, do not answer this post questioning whether I should or I should not need to run a project even if it does not compile. please.

If not possible in IntelliJ, is it possible in maven? How?

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

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

发布评论

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

评论(10

々眼睛长脚气 2024-12-11 16:52:49

在 Intellij 12 中,您还可以选择以下选项(我个人认为这是最好的一个):

  • 转到编辑启动器的配置
  • 转到启动前部分
  • 如果“Make”在列表中:将其删除
  • 添加“Make,无错误检查”现在

,当您运行时,make 仍会自动完成,但即使出现编译错误,运行也会继续。

关于上述争论;我认为,即使代码的另一部分不能编译,也能运行能够编译的代码部分,这是非常有意义的;例如,如果代码的其他部分属于项目中的模块但在运行时不涉及。

In Intellij 12 you also have the following option (which personally I find the best one):

  • Go to Edit configuration of your launcher
  • Go to the before launch section
  • If 'Make' is in the list: remove it
  • Add 'Make, no error check'

Now, when you run, a make will still be done automatically but the run will continue even if the are compilation errors.

Regarding the above debate; I think it makes perfect sense to be able to run a part of the code that does compile even if another part of the code does not not; e.g. if that other part of the code belongs to a module that is in your project but not involved when running.

这样的小城市 2024-12-11 16:52:49

我今天在工作中遇到了同样的问题。在此之前,我可能会很快追随“你为什么要这么做?”的潮流。事实证明,Eclipse 正是可以让您做到这一点,并且如果您开始与依赖此功能的其他开发人员同时工作(也就是说,签入无法编译的代码),那么能够很方便地在主意!

对于我们 IDEA 用户来说幸运的是,你可以。按照 Eclipse 用户常见问题解答中的说明进行操作,就可以开始了:

为了能够运行有错误的代码,您可以选择 Eclipse
在“设置”对话框、“编译器”、“Java 编译器”中添加编译器
编译器的附加命令行参数的 -proceedOnError 选项。

唯一的缺点是它不像 Eclipse 那样无缝。首先,您必须取消选中“运行前生成”选项,因为如果 make 失败,IDEA 将不会运行。然后,您必须记住在运行之前进行构建。不过,有了这些警告,您应该能够完成您所追求的目标。

I ran into this exact same problem at work today. Before now, I probably would have been quick to jump on the bandwagon of, "Why would you ever want to do that?" Turns out that Eclipse lets you do exactly this, and if you start working concurrently with other developers who depend on this feature (which is to say, check in code that doesn't compile), it's handy to be able to do the same in IDEA!

And lucky for us IDEA users, you can. Follow these instructions from the FAQ for Eclipse Users, and you're good to go:

To be able to run code with errors, you can select the Eclipse
compiler in Settings dialog, Compiler, Java Compiler and add the
-proceedOnError option to the Additional command line parameters for the compiler.

The only thing that's lame is that it's not quite as seamless as in Eclipse. First, you'll have to untick the option to Make before run because IDEA won't run if make fails. Then, you'll have to remember to build before running. With those caveats, though, you should be able to accomplish what you're after.

纵性 2024-12-11 16:52:49

Stijn Geukens 的答案是正确的,但可以改进。
在 Intellij Idea 版本 12 中,可以将其替换为“Make,无错误检查”,而不是删除“Make”规则。这样项目将被重建(编译器将尝试这样做),但它将独立于编译结果运行程序。

Stijn Geukens's answer is correct, but it can be improved.
In Intellij Idea version 12 instead of removing the "Make" rule it can be replaced with "Make, no error check". This way project will be rebuilt (compiler will atempt to do it), but it will run the program independently of compile outcome.

神经暖 2024-12-11 16:52:49

如果您只想调试一个部分,那么您可以围绕它创建一个单元测试。如果你不使用不能编译的类,那么你仍然可以调试单元测试相关的代码。

If you want to debug just one part, then you can create a unit test around that. If you do not use the class that does not compile, then you can still debug the unit test related code.

乖乖公主 2024-12-11 16:52:49

当出现编译错误时,您可以从编译中排除特定文件。

  • 转到消息窗口(如果不可见:查看 -> 工具窗口
    ->消息)
  • 右键单击问题文件
  • 从编译中排除

When there are compilation errors, you can exclude specific files from compilation.

  • Go to the Messages window (if it is not visible: View -> Tool Windows
    -> Messages)
  • Right click the problem file
  • Exclude from compile
一念一轮回 2024-12-11 16:52:49

至少在 Intellij 12 中你可以实现这一点。

  • 首先尝试编译项目,包括损坏的类。
  • 然后在 Messages 视图中,包含所有编译错误:
    • 右键单击要排除的类
    • 点击“从编译中排除”

请参阅此问题 关于之后如何重新包含。

At least in Intellij 12 you can achieve this.

  • First try to compile the project, including the broken class(es).
  • Then in the Messages view, containing all the compile errors:
    • Right-click the class you want to exclude
    • Click 'exclude from compile'

See this question on how to reinclude afterwards.

零崎曲识 2024-12-11 16:52:49

对于Intellij 2017.3.1,我的配置是这样的:

  1. 使用Eclipse编译器:设置->构建、执行、部署 ->编译器-> Java编译器->使用编译器:Eclipse
  2. 选择“出现错误时继续”,
  3. 在启动构建,无错误检查之前编辑所需的默认配置(我将其用于 JUnit): 检查此屏幕截图
  4. 附加步骤,以便 Intellij 在运行配置时不会打开有错误的类。在设置 -> 中取消选择自动在编辑器中显示第一个错误构建、执行、部署 ->编译器

PS:此配置并不适合所有用途。仅当您修复因实现代码更改而失败的单元测试时,它才有效。当您返回实现功能时,禁用此功能更有用,因为它会让您运行有错误的实现代码,并且不会跳转到编译错误。您需要反复更改 Eclipse 编译器和 Javac 编译器以获得最佳结果。

For Intellij 2017.3.1 my configuration is like this:

  1. Use the Eclipse Compiler: Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Use compiler: Eclipse
  2. Select "Proceed on errors"
  3. Edit your desired configuration defaults (I use this for JUnit) before launch to Build, no error check: Check this screenshot
  4. Additional step in order for Intellij not to open the classes with errors when you run your configuration. Un-select Automatically show first error in editor in Settings -> Build, Execution, Deployment -> Compiler

PS: This configuration is not perfect for all usages. It only works when you are fixing unit tests that were failing because of your changes in implementation code. When you go back to implementing features it is more useful to disable this feature since it will let you run you implementation code with errors and it will not jump to compilation errors. You need to go back and forth with changing the Eclipse compiler with the Javac one for best results.

不一样的天空 2024-12-11 16:52:49

哇,我已经有一段时间没有使用 IntelliJ 了,我非常想念它!根据我的记忆,只要模块中的其余文件编译,您应该能够右键单击模块中的 main 方法并直接运行它。我认为同一项目中的第二个模块出现错误并不重要。这不适合你吗?

Wow, it's been a while since I've been in IntelliJ and I miss it dearly! From my recollection you should be able to right click the main method in a module and run it directly so long as the remainder of the files in the module compile. I don't think it matters that a second module in the same project has errors. Is that not working for you?

何其悲哀 2024-12-11 16:52:49

更新版本 2017 - 2.5 社区,因为菜单选项略有不同

导航至:

编辑配置

运行/调试配置窗口底部附近的运行 >

查找“启动前:激活工具窗口”

此标题下方的字段列出了您当前的构建配置设置。

使用 + 和 - 符号添加和删除构建首选项。

完成后

选择“应用”,然后

就可以了!

updating for version 2017 - 2.5 community as menu options are slightly different

Navigate to:

Run>Edit Configurations

near the bottom of the Run/debug config window look for

"before launch: Activate tool window "

the field below this heading lists your current build config settings.

Use the + and - symbols in order to add and remove build preferences.

Once completed

Select apply then Okay

Thats it!

2024-12-11 16:52:49

我认为这根本不可能。如何运行无法编译的东西?这就像驾驶一辆没有组装好的汽车一样。您可以注释掉不编译的文件,以便项目编译...

让 Intellij 不将文件计为源代码

编辑 - 或者您可以通过右键单击您的项目 -> 打开模块设置->选择您的模块 ->选择文件->排除

I don't think its possible at all. How you can run something that doesn't compile? That would be like driving a car that isn't put together. You could comment out the files that don't compile, so that the project compiles....

Edit -- or you can have Intellij not count the file as source by

Right Click on your project -> open module settings -> select your module -> select the file -> excluded

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