昨天我从Eclipse切换到IntelliJ IDEA。
我也在使用JRebel和WebSphere Server 7。
现在一切似乎都工作得很好,除了当我修改Java文件并点击保存时,IntelliJ不会重新编译文件,以便JRebel接收它。
Eclipse“自动构建”功能解决了这个问题。
在IntelliJ IDEA中,我必须按CTRL + SHIFT + 9重新编译JRebel的相关类才能获取它。如果跨两个文件进行了更改,我必须在每个文件和其中一个文件上执行此操作,并且由于IntelliJ使用了save all机制,因此很难知道手动重新编译的内容,我也不感兴趣。
难道没有办法使IntelliJ自己做到这一点吗?
对于IntelliJ IDEA 12+版本,如果我们使用外部编译器选项,我们可以自动构建已编辑的源。唯一需要的是检查位于“编译器”设置下的“自动构建项目”选项:
此外,如果您希望热部署,在应用程序运行时或者如果您使用的是spring boot devtools,则还应该从注册表启用compiler.automake.allow.when.app.running
。这将自动编译您的更改。
使用Ctrl + Shift + A(或Mac上的⌘+ Shift + A)键入Registry
一旦注册表窗口打开,找到并启用compiler.automake.allow.when.app.running
,请参见此处:
有关更多提示,请参阅"Migrating From Eclipse to IntelliJ IDEA"指南。
当Intellij遇到其他模块中的编译问题时,它会安静地失败,然后不执行自动构建。所以检查你的Problems
窗口
使用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());
}
我收到错误:一些罐子不在classpath中。所以我只是删除损坏的jar并在步骤下执行
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
我遇到过同样的问题。我正在使用“省电模式”,这可以防止逐步编译并显示编译错误。
没有足够的点来评论现有的答案,但与上面的一些人类似,我最后只是添加了一个宏和键盘映射到Organize Imports / Format / SaveAll / FastReload(F9)/ Synchronize。
添加同步,因为它似乎是我还能看到外部构建工具/观察者(即webpack)修改的资源更新的唯一方法。
这个过程比eclipse慢 - 并且对于外部文件刷新经常需要多次运行命令 - 但是假设我可以忍受它。
请遵循以下两个步骤:
make project automatically
Make Project automatically
功能Registry
compiler.automake.allow.when.app.running
并启用它或单击它旁边的复选框注意:立即重启您的应用程序:)
注意:这也应允许使用spring boot devtools进行实时重新加载。
Eclipse Mode插件已过时,与最近的IDEA 12+版本不兼容。如果您安装它,IDE将挂起每个文件更改并将响应非常慢。
IntelliJ IDEA不使用自动构建,它会动态检测错误,而不是通过编译器。类似于Eclipse模式将在IDEA 12中提供:
使用Build
| Make
,它调用增量make进程,只编译已更改的和依赖文件(它非常快)。
还有一个可能有帮助的FAQ entry。
更新自动make功能:运行/ debug配置运行时,Make project automatically
无效。磁盘上的类只会在Build
上更改Make
。这是核心设计决策,因为在我们看来,磁盘上的类更改应该始终在用户的控制之下。自动make不是Eclipse功能的模板,它的工作方式不同,它的主要目的是节省等待类真正需要时(在运行应用程序或测试之前)的时间。自动make不会替换您仍然需要触发的显式编译,就像在本问题中描述的情况一样。如果您正在寻找不同的行为,那么在上面的FAQ中链接的EclipseMode插件将是更好的选择。
您可以键入映射ctrl+s
以一步保存和编译。转到键盘设置并搜索Compile
。
我最后录制了一个宏来保存和编译一步,并将keymap Ctrl+s
添加到它。
实际上没有区别,因为两者都需要1次点击:
最简单的解决方案就是习惯它。因为当你在IDE中花费大部分时间时,最好在一个人中养成快速习惯,而不是在其中一些习惯中放慢习惯。
我设法使用宏来解决这个问题。
我开始录制一个宏:
将它命名为“SaveAndMake”。
现在只需删除Save all keybinding,并将相同的键绑定添加到宏中!
所以现在,每次我保存,它都会保存并进行脏编译,jRebel现在可以正确检测所有更改。
请仔细按照以下步骤启用它。
1)使用SB V1.3创建Spring Boot项目,并将“Devtools”(1 *)添加到依赖项
2)调用Help-> Find Action ...并输入“Registry”,在对话框中搜索“automake”并启用条目“compiler.automake.allow.when.app.running”,关闭对话框
3)在设置 - >构建,执行,部署 - >编译器“自动生成项目”中启用后台编译
4)打开Spring Boot运行配置,如果一切配置正确,你应该收到警告信息
5)运行您的应用程序,即时更改您的课程
请将您的经历和问题报告为此问题的评论。