昨天我从Eclipse切换到IntelliJ IDEA。

我也在WebSphere Server 7中使用JRebel。

现在一切似乎都运行得很好,除了当我修改一个Java文件并点击保存时,IntelliJ不会重新编译文件,以便JRebel拾取它。

Eclipse的“自动构建”特性解决了这个问题。

在IntelliJ IDEA中,我必须按CTRL+SHIFT+9来重新编译JRebel的相关类。如果跨两个文件进行更改,我必须在每个文件上都这样做,因为IntelliJ使用了保存所有机制,很难知道手动重新编译什么,我也不感兴趣。

难道没有办法让IntelliJ自己来做这个吗?


当前回答

请仔细执行以下步骤来启用它。

1)使用SB V1.3创建Spring Boot项目,并将“Devtools”(1*)添加到依赖项中

2)调用Help->查找动作…输入“Registry”,在对话框中搜索“automake”,并启用“compiler. autommake .allow.when.app.running”条目,关闭对话框

3)在设置->构建,执行,部署->编译器“自动制作项目”中启用后台编译

4)打开Spring Boot运行配置,如果一切配置正确,你应该得到警告信息

5)运行应用程序,实时更改课程

请将您的经验和问题以评论的形式报告给我们。

点击这里了解更多信息

其他回答

请仔细执行以下步骤来启用它。

1)使用SB V1.3创建Spring Boot项目,并将“Devtools”(1*)添加到依赖项中

2)调用Help->查找动作…输入“Registry”,在对话框中搜索“automake”,并启用“compiler. autommake .allow.when.app.running”条目,关闭对话框

3)在设置->构建,执行,部署->编译器“自动制作项目”中启用后台编译

4)打开Spring Boot运行配置,如果一切配置正确,你应该得到警告信息

5)运行应用程序,实时更改课程

请将您的经验和问题以评论的形式报告给我们。

点击这里了解更多信息

我最终录制了一个宏来保存并在一步中编译,并按Ctrl+s键映射到它。

对于那些使用新的Intellij版本却找不到compiler. autommake .allow.when.app.running的人

https://youtrack.jetbrains.com/issue/IDEA-274903

基本上选项现在已经移动到设置->高级设置->编译器(检查允许自动生成选项)

使用Reformat and Compile插件(灵感来自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());
}

更新

对于IntelliJ IDEA 12+版本,如果我们使用外部编译器选项,我们可以自动构建编辑过的源代码。唯一需要做的就是勾选位于“编译器”设置下的“自动构建项目”选项:

此外,如果你想在应用程序运行时热部署,或者如果你使用spring boot devtools,你也应该从注册表中启用compiler. autommake .allow.when.app.running。这将自动编译您的更改。

对于大于2021.2的版本,我们需要勾选“即使开发应用程序正在运行,也允许自动启动”选项:

对于2021.2之前的版本:

使用Ctrl+Shift+A(或Mac上的⌘+Shift+A)键入Registry,一旦注册表窗口打开,找到并启用compiler. autommake .allow.when.app.running,参见这里:


For versions older than 12, you can use the *EclipseMode* plugin to make IDEA automatically compile the saved files.

有关更多提示,请参阅“从Eclipse迁移到IntelliJ IDEA”指南。