Intellij IDEA Java类不保存时自动编译

昨天我从Eclipse切换到Intellij。

我也使用jsp与Websphere Server 7。

现在一切似乎都工作得很好,除了当我修改一个Java文件,并保存 ,Intellij 重新编译该文件,以便jRebel拿起它。

日蚀“ 自动构build ”function解决了这个问题。

在Intellij中,我必须按CTRL + SHIFT + 9才能重新编译jRebel的相关类来提取它。 如果在两个文件之间进行更改,我必须在每个 文件 上执行此操作,而且因为Intellij使用了save all机制,所以很难知道手动重新编译的内容。

没有办法让Intellij自己做这个吗?

更新
对于IDEA 12+版本,如果使用外部编译器选项,我们可以自动编译编辑的源代码。 唯一需要的是检查“编译器设置”下的“自动生成项目”选项。 编译器设置


对于12以前的版本,可以使用EclipseMode插件使IDEA自动编译保存的文件。 从Eclipse迁移时,请参阅https://www.jetbrains.com/help/idea/2016.3/eclipse.html以获取更多提示。;

警告

Eclipse模式插件已经过时,并且与最近的IDEA 12+版本不兼容。 如果你安装它,IDE会挂在每一个文件的变化,并会响应非常缓慢。


IntelliJ IDEA不使用自动构build,它可以即时检测错误,而不是通过编译器。 与IDEA 12中的 Eclipse模式类似:

自动进行项目

使用Build | Make ,它会调用增量make过程,它只会编译更改和相关的文件(非常快)。

还有一个常见问题条目 ,可能会有所帮助。

自动生成function的更新 :当运行/debuggingconfiguration正在运行时, Make project automatically不起作用。 磁盘上的类只会在Build |上更改 Make 。 这是核心devise决定,因为我们认为磁盘上的class级变更应该始终在用户的控制之下。 自动make不是Eclipse特性的复制模式,它的工作原理是不同的,主要目的是节省时间等待真正需要的类(在运行应用程序或testing之前)准备好。 自动make并不能代替你在这个问题中描述的情况下仍然需要触发的显式编译。 如果您正在寻找不同的行为,则上述FAQ中链接的EclipseMode插件将是更好的select。

1 – 从编译器启用Automake

  • 按: ctrl + shift + A (对于Mac⌘ + shift + A
  • types: make project automatically
  • 点击: input
  • 启用Make Project automaticallyfunction

2 – 在应用程序运行时启用Automake

  • 按: ctrl + shift + A (对于Mac⌘ + shift + A
  • types: Registry
  • find关键的compiler.automake.allow.when.app.running启用它,点击旁边的checkbox

注意:现在重新启动您的应用程序:)

注意:这也应该允许使用spring引导devtools实时重新加载。

你可以键盘映射ctrl+s一步保存和编译。 转到键映射设置并searchCompile

我最终录制了一个macros来保存和编译一步,并按Ctrl+s键。

实际上没有区别,因为两者都需要点击一下:

  • Eclipse :手动保存,自动编译。
  • IntelliJ :自动保存,手动编译。

最简单的解决scheme就是习惯它。 因为当你在你的IDE中度过大部分白天的时候,最好有一个习惯,而不是一些慢的习惯。

我设法解决这个使用macros。

我开始录制一个macros:

  • 点击编辑 – macros – 开始macros录制
  • 单击文件 – 全部保存
  • 点击Build – Make Project
  • 单击编辑 – macros – 停止macroslogging

将其命名为“SaveAndMake”。

现在只要删除保存所有的键盘绑定,并将相同的键盘绑定到您的macros!

所以,现在,每次我保存时,它都会保存并进行脏编译,jRebel现在可以正确检测到所有更改。

请仔细按照这些步骤启用它。

1)用SB V1.3创buildSpring Boot项目,并添加“Devtools”(1 *)到依赖关系

2)调用帮助 – >查找操作…并键入“registry”,在对话框中search“automake”并启用条目“ compiler.automake.allow.when.app.running ”,closures对话框

3)在Settings-> Build,Execution,Deployment-> Compiler“自动生成项目”中启用后台编译

4)打开Spring Boot run config,如果一切configuration正确,你应该得到警告信息

5)运行你的应用程序,即时改变你的课程

请将您的经验和问题报告为对此问题的评论。

点击这里查看更多信息

使用重新格式化和编译插件(受Alexandre DuBreuil的Save Actions插件启发):

https://plugins.jetbrains.com/plugin/8231?pr=idea_ce

目前我只提供一个jar文件,但这是代码中最重要的部分:

 private final static Set<Document> documentsToProcess = new HashSet<Document>(); private static VirtualFile[] fileToCompile = VirtualFile.EMPTY_ARRAY; // The plugin extends FileDocumentManagerAdapter. // beforeDocumentSaving calls reformatAndCompile private static void reformatAndCompile( @NotNull final Project project, @NotNull final Document document, @NotNull final PsiFile psiFile) { documentsToProcess.add(document); if (storage.isEnabled(Action.compileFile) && isDocumentActive(project, document)) { fileToCompile = isFileCompilable(project, psiFile.getVirtualFile()); } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (documentsToProcess.contains(document)) { documentsToProcess.remove(document); if (storage.isEnabled(Action.optimizeImports) || storage.isEnabled(Action.reformatCode)) { CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { @Override public void run() { if (storage.isEnabled(Action.optimizeImports)) { new OptimizeImportsProcessor(project, psiFile) .run(); } if (storage.isEnabled(Action.reformatCode)) { new ReformatCodeProcessor( project, psiFile, null, ChangeListManager .getInstance(project) .getChange(psiFile.getVirtualFile()) != null) .run(); } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(psiFile); } }); } }); } } if (fileToCompile.length > 0) { if (documentsToProcess.isEmpty()) { compileFile(project, fileToCompile); fileToCompile = VirtualFile.EMPTY_ARRAY; } } else if (storage.isEnabled(Action.makeProject)) { if (documentsToProcess.isEmpty()) { makeProject(project); } } else { saveFile(project, document, psiFile.getVirtualFile()); } } }, project.getDisposed()); } private static void makeProject(@NotNull final Project project) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { CompilerManager.getInstance(project).make(null); } }, project.getDisposed()); } private static void compileFile( @NotNull final Project project, @NotNull final VirtualFile[] files) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { CompilerManager.getInstance(project).compile(files, null); } }, project.getDisposed()); } private static void saveFile( @NotNull final Project project, @NotNull final Document document, @NotNull final VirtualFile file) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); if (fileDocumentManager.isFileModified(file)) { fileDocumentManager.saveDocument(document); } } }, project.getDisposed()); } 

在我的maven项目中,唯一影响到我的是为我的unit testing的运行configuration添加一个“testing编译”的目标。 令人难以置信的笨拙解决scheme,但它的工作原理。

在这里输入图像描述

当Intellij在其他模块中遇到编译问题时,Intellij悄然失败,然后不执行自动构build。 所以检查你的Problems窗口

没有足够的评论现有的答案,但类似于上面的一些人,我最后只是增加一个macros和键盘映射到组织import/格式/ SaveAll / FastReload(F9)/同步

同步被添加,因为它似乎是唯一的方式,我也可以看到由外部构build工具/观察者(即webpack)修改的资源的更新。

这个过程比eclipse慢 – 而且外部文件刷新通常需要多次运行命令 – 但是假设我可以忍受它。

我遇到过同样的问题。 我正在使用“省电模式”,它防止增量编译和显示编译错误。