If you open up a class with a publis static void main(String[] args) {} method in Eclipse and hit run, then that class will run. If you move to another class with its own main() method and hit run, then that class will run. Is this possible in IntelliJ IDEA? Or will I have to manually change Run configuration every time I want to run something other than the current run configuration?
You can right click on the class in the Project view and select 'Run YourMainClass.main()'
Alternatively in the text editor with that class open you can right click anywhere in the window and select 'Run YourMainClass.main()'.
Or if you don't want to right click there's a shortcut too (should be displayed in the right click menu - differs by OS)
Doing this will save a configuration in the dropdown as well, so if you go in the edit configurations dialog there you can add vm parameters or any options that need to differ from the default. Configurations created like this have a semi-transparent icon to differentiate them.
Related
When creating a new java class via new -> Java Class while using IntelliJ IDE, a random Dialog started appearing, and I can't find how to disable it.
This is the strange dialog that started showing, a sort of a wizard. Clicking the help button get's me There is no help for this dialog message.
How can I disable this window in the Intellij IDEA?
I too had the same problem, the exact same dialog. In my case, it actually ended up not being a bug, but IJ acting properly (kinda).
TL;DR: The template code for creating a "Class" object got automagically changed after an IJ update so that it would prompt for answers from the coder when creating a new class file. Changing it back in "Settings/File and Code Templates" to the default template code removes the problem, as the default template code does not use any variables that are prompted for upon class object creation (ex.: ${IMPORT_BLOCK}).
Long version ...
Bring up the Settings dialog for IJ, and in the search field type "template", and then select the "File and Code Templates" option. You'll see on the right side of the dialog the "Editor > File and Code Templates" area. If you select "Class" from the list of template types, to the right of that list of template types you'll see the template used when you create a class ...
Now I don't know why, but after a particular IJ update some months back, via their Toolbox app, the default template text/code was different, so that it looked like this ...
... and that latter template code/text caused the second dialog to appear that you see.
To fix the problem, highlight the "Class" template from the list, then click on the "Reset to Default" button that appears below the Files/Includes/Code/Other tabs (looks like a piece of paper with a 180 degree curving arrow on top of it), so that the template text goes back to what I have showing in the first screenshot, and then select the OK button.
Assuming your "default" template for the Class template is not corrupted/bad, you should no longer see the dialog that you asked about.
Go to Settings/File and Code Templates -> class and change it to:
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}
You can also try hitting the reset to default button, as Adrian Romanelli suggested.
Usually, I will want to display the code usage like class hierarchy and etc. And it will override the Run view. But afterwards, I want to get back to Run view to check logs. Is there any quick way to do that ? Now I have to close class hierarchy view and then open Run view which is time consuming
Most toolwindows in IntelliJ IDEA have shortcuts that can be used for activating them. You can see the shortcuts if you open the View | Tool Windows submenu of the main menu.
The default shortcut for the Run toolwindow is Alt-4 in the default keymap or Cmd-4 in the Mac OS X 10.5+ keymap.
I was wondering how I might configure Intelliji IDEA to automatically make my code look like:
public void Something()
{
// something
}
rather than:
public void Something() {
// something
}
I believe it is called the "Allman" style. Intelliji comes out of box using the "K&R" (I think?) style, however.
go to project settings. configure code style formatting.
To do Allman for Java (newbie-ish version) go to File/Settings/Editor/Code Style/Java. Next select the Wrapping and Braces tab and expand Braces placement. Now you must click 'End of line' for all three choices and select 'Next line' for each in the box that appears. Then click apply and OK.
I know this question is already answered, but to save people from actually modifying the settings.
Here is the AllmanIndent.xml download the .zip file.
After you download and extract the zip do the following steps:
From IntelliJ go to File->Settings->Editor->Code-Style and click the gear icon by the "Scheme" and then click on "Import Scheme -> IntelliJ code style XML" and then choose the extracted .xml file.
After this import, you can press Ctrl+Alt+L to auto-indent code.
I am working to make an Eclipse Plugin. I used a plugin project template that generated a View class which extends ViewPart. I think that it is part of SWT.
My problem is that the View is like a window inside of the main Frame which has buttons for close, minimize. I clicked on the X button of the View by mistake. Now I cannot make it visible again even if I relaunch the Eclipse Application.
Now, my Eclipse application looks like this:
It had some panels and buttons before. But I cannot make the View visible again. How should I make to bring it back? I have tried to delete the plugin project from Eclipse and import it again. But it did not work.
I bet that there it is an easy way to make the View visible again but I do not know how. Is there any setting through MANIFEST file? Or other file?
Specify the -clearPersistedState argument when you run the RCP (this assumes you are using Eclipse 4.x).
1) quick solution
restart workbench with clear workspace option checked under run configuration ..
2) Full Solution
you should add a menu in menu bar to open your view so that you can open your view when ever you want
create a command say openMyMenu
create a handler for it and call below code from handler execute method.
add that command to main menu bar..
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(<view ID>);
Intellij does not seem to be doing basic hot code swap on my installation.
For this code:
public class MainTest {
public void method1() {
System.out.println("Breakpoint here");
}
public void method2() {
System.out.println("Line that will get 24 modified");
}
public static void main(String[] args) {
System.out.println("First print here");
MainTest mainTest = new MainTest();
mainTest.method1();
mainTest.method2();
System.out.println("Line that I do not modify");
}
}
I put a breakpoint on mainTest.method1(); then modify the string at method2(), hit ctrl+s and continue to step by step. Unfortunately the runtime is not updated, old string is being printed. Full stop - compile - run does print the new string. So my conclusion is hot-swap not working.
Is there any settings I need to set to enable hot code swap?
Ubuntu, JDK 1.6
Intellij 10.5 Ultimate (evaluation)
After saving your class while waiting on your breakpoint just recompile your class with Build -> Compile 'MainTest.java' or press Ctrl+Shift+F9 with the standard key bindings.
IntelliJ IDEA will then show a small dialog in which it asks you if you want to reload that class.
After below modifications and enabling hot swap, a change in a Java file took 1-2 seconds of restart time. (Initial start time is around 7 seconds for me).
I hope below method helps...
First, you need to check “Make project automatically” in preferences menu.
To open preferences menu;
you can go to top menu and click;
IntelliJ IDEA -> Preferences
or you can type below shortcut via keyboard;
cmd + option + s
Then, you can check Make project automatically as in below picture;
Secondly, you need to modify compiler.automake.allow.when.app.running registry setting as true.
To open registry, you need to click below keyboard shortcut:
cmd + shift + a
Type registry as in below picture, select Registry, and hit enter button of keyboard;
After Registry window opened, type compiler.automake to see compiler.automake.allow.when.app.running option, and check it as in below picture;
Then, you need to restart IntelliJ to make registry changes work.
There is a Debugger > HotSwap option in intellij 11.
Go to Setting --> Select Debug --> HotSwap
I wanted hotswap to automatically run every time I saved a Java file. None of the other answers did this so I just:
Created a macro that will run on save: https://stackoverflow.com/a/5581992/14731
Added Action: Hotswap at the end of the macro (Run -> Reload Changed Classes)
I think you are asking about this,
Right-click on your java class
Select Compile And Reload File
For anyone experiencing the same problem as me, you might have incurred in the following recent bug affecting the 2020.2 update: https://youtrack.jetbrains.com/issue/IDEA-247530?_ga=2.116305920.729836936.1599654650-984156210.1599654650
TL;DR As a workaround, you need to re-activate the Groovy plugin.
I encountered this problem on Ubuntu. I also had an apparently unrelated issue where IntelliJ gave an error about the file watch limit (my apologies that I no longer have the exact error message). To solve this later issue I did the following steps:
Add the following line to either /etc/sysctl.conf file or a new *.conf file (e.g. idea.conf) under /etc/sysctl.d/ directory:
fs.inotify.max_user_watches = 524288
Then run this command to apply the change:
sudo sysctl -p --system
Now my React components rebuild and hot swap just fine.
Source