Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Intellij IDEA Java类在保存时不自动编译_Java_Jakarta Ee_Intellij Idea_Jrebel - Fatal编程技术网

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

Intellij IDEA Java类在保存时不自动编译,java,jakarta-ee,intellij-idea,jrebel,Java,Jakarta Ee,Intellij Idea,Jrebel,昨天我从Eclipse切换到IntelliJ IDEA 我也在WebSphereServer7中使用JRebel 现在一切似乎都运行得很好,除了当我修改一个Java文件,并点击save时,IntelliJ不会重新编译该文件,以便JRebel能够获取它 Eclipse“自动构建”功能解决了这个问题 在IntelliJ IDEA中,我必须按CTRL+SHIFT+9来重新编译相关类,以便JRebel将其提取出来。如果更改跨两个文件进行,我必须对每个文件和其中一个文件进行更改,而且由于IntelliJ使

昨天我从Eclipse切换到IntelliJ IDEA

我也在WebSphereServer7中使用JRebel

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

Eclipse“自动构建”功能解决了这个问题

在IntelliJ IDEA中,我必须按CTRL+SHIFT+9来重新编译相关类,以便JRebel将其提取出来。如果更改跨两个文件进行,我必须对每个文件和其中一个文件进行更改,而且由于IntelliJ使用“全部保存”机制,因此很难知道手动重新编译什么,我也不感兴趣

有没有办法让IntelliJ自己做这件事 对于IntelliJ IDEA 12+版本,如果使用外部编译器选项,我们可以自动构建编辑过的源代码。只需选中“编译器”设置下的“自动生成项目”选项:

另外,如果您想在应用程序运行时进行热部署,或者如果您使用的是spring boot devtools,那么您也应该从注册表启用
编译器.automake.allow.when.app.running
。这将自动编译您的更改

使用Ctrl+Shift+A(或⌘+Mac上的Shift+A)键入
注册表
打开注册表窗口后,找到并启用
compiler.automake.allow.when.app.running
,请参阅此处:


对于早于12的版本,您可以使用EclipseMode插件使IDEA自动编译保存的文件

有关更多提示,请参阅指南。

警告 Eclipse模式插件已过时,与最近的IDEA 12+版本不兼容。如果安装它,IDE将挂在每个文件更改上,并且响应速度非常慢


IntelliJ IDEA不使用自动构建,它动态检测错误,而不是通过编译器。类似于Eclipse的模式将在以下位置提供:

使用
Build
|
Make
,它将调用增量Make过程,该过程将只编译更改的和依赖的文件(速度非常快)

还有一种方法可能会有所帮助

自动生成功能的更新
运行运行/调试配置时,
自动生成项目
无效。磁盘上的类将仅在
生成
|
生成
时更改。这是核心设计决策,因为我们认为磁盘上的类更改应该始终由用户控制。Automatic make不是Eclipse特性的复制品,它的工作方式不同,它的主要目的是节省等待类在真正需要时准备好的时间(在运行应用程序或测试之前)。Automatic make不会取代您仍然需要触发的显式编译,如本问题所述。如果您正在寻找不同的行为,那么上面常见问题中链接的EclipseMode插件将是一个更好的选择。

您可以通过键入map
ctrl+s
一步保存和编译。转到“键映射设置”并搜索
Compile

我最终录制了一个宏来保存和编译,并将其键映射到
Ctrl+s

我也遇到了同样的问题。
我使用的是“节能模式”,它可以防止增量编译和显示编译错误。

我设法用宏解决了这个问题

我开始录制宏:

  • 单击编辑-宏-开始宏录制
  • 单击文件-全部保存
  • 单击Build-makeproject
  • 单击编辑-宏-停止宏录制
给它起个有用的名字,比如“SaveAndMake”

现在只需删除SaveAll键绑定,并将相同的键绑定添加到宏中


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

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

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

最简单的解决办法就是适应它。因为当你白天大部分时间都在IDE中时,最好在其中一个环境中养成快习惯,而不是在其中几个环境中养成慢习惯。

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

目前我只提供一个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());
}
private final static Set documentsToProcess=new HashSet();
私有静态虚拟文件[]fileToCompile=VirtualFile.EMPTY_数组;
//该插件扩展了FileDocumentManagerAdapter。
//在DocumentSave调用之前,请重新格式化并编译
私有静态void reformatAndCompile(
@非空最终项目,
@非空最终文件,
@NotNull最终PSI文件(PSI文件){
documentsToProcess.add(文档);
if(storage.isEnabled(Action.compileFile)和&isDocumentActive(project,document)){
fileToCompile=isFileCompileable(项目,psiFile.getVirtualFile());
}
ApplicationManager.getApplication().invokeLater(新的Runnable()){
@凌驾
公开募捐{
if(documentsToProcess.contains(文档)){
文档停止处理。删除(文档);
if(storage.isEnabled(Action.optimizeImports)
||存储.isEnabled(操作.重新格式化代码)){
CommandProcessor.getInstance().runUndoTransparentAction(新的Runnable()){
@凌驾
公开募捐{
if(storage.isEnabled(Action.optimizeImports)){
新处理器(项目,
1.Project >  Setting>Build,Execution,Deployment>Compiler>check build project automatically
2.CTRL+SHIFT+A find/search **registry** --Check for below param
compiler.automake.allow.when.app.running
compiler.automake.trigger.delay=500---According to ur requirement
3.Add devtool in pom.xml
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
4.Build ,If found any probelm while building ,saying some jar in not in class path.Just delete the corrupted jar
and re-build the project angain after sync with maven lib