How do I set up IntelliJ IDEA to redeploy changed resources? - java

I use IntelliJ IDEA and want that my class should be redeployed after I make changes. Eclipse can do this. How does this work in IDEA?
I know that in the run configuration there is "On frame deactivation" and I set it to "Update classes and resources", but this does not work.
Do you hit the "redeploy" button every time you made a change in your class?

There are limitations to class reload, in any Java project. It also depends on what you're using to perform this reload (if you're using a servlet container, etc).
By default, IntelliJ uses HotSwap for its reloading. There are some limitations to it though:
At the moment due to original limitations of Java SDK the HotSwapping is possible ONLY if a method body is altered. In all other cases (like changing method or class signature), the class reload is impossible and the corresponding error message appears.
That said, the instructions for configuring your application to reload can be found here.
To configure reloading behavior
On the main menu, choose File | Settings , and then expand the Debugger node.
Open HotSwap page.
Click one of the radio buttons in the group Reload classes after compilation. You can opt to always reload classes, reload after
confirmation, or never do it.

Take a look at HotswapAgent configuration for InteliJ IDEA

Related

Changing variables in realtime when debugging in intellij?

When debugging in eclipse, I believe you are able to change the value of a variable in the source and have it update in realtime without setting breakpoints or anything. I was wondering if the same was possible in intellij?
Same question but for eclipse.
You can reload classes while running your program in Debug mode and changes in code will apply if possible (there are limitations) without restarting the program.
To reload changed classes
Do one of the following:
On the main menu, choose Run -> Reload Changed Classes.
On the main menu, choose Build -> Compile "class_name" to recompile an altered class during debug.
Not aware about any other method to change the value of a variable "in real-time".
Yes, IntelliJ IDEA allows you to see real-time changes while debugging Java code. This feature is called HotSwap, and it allows you to modify your code while the program is running, without the need to stop and restart the debugger.
To use HotSwap in IntelliJ IDEA, you first need to enable it by going to the Run/Debug Configuration dialog and selecting the configuration for your application. Then, in the "Debug" tab, make sure the "Enable HotSwap" option is checked.
To use HotSwap, simply make your code changes in the editor and then press Ctrl+F9 (Windows/Linux) or Command+F9 (macOS) to compile and reload the code in the running program.
Note that not all changes can be applied using HotSwap. Some changes, such as changes to class hierarchies or changes to method signatures, will require a full restart of the debugger. Additionally, HotSwap is not supported in all Java virtual machines, so make sure to check the compatibility of your JVM if you encounter any issues

Is it possible to save the workspace between different (Plugin) runs?

I want to manually test some features of a plugin I'm developing. To do so, it'd be nice to be able to create some projects in the test Eclipse instance and have them stay throughout all my testing season. At the moment it seems that Eclipse insists on clearing the Eclipse Plugin workspace. Is it possible to invert its default behavior?
Thanks
Open up the launch configuration for this launch
On the Main tab, unclick Clear so the workspace remains across launches (alternatively, you can select Ask for confirmation... so you can choose each time).
As far as I know, there is no way to mark this as the default.

Refreshing Swing application with Eclipse/MyEclipse

Say that we are writing a Java Swing application and we use Eclipse or MyEclipse to develop it. In web applications, you make code changes, you save and your ant deployment file takes care of the deployment of the changed files. Then you just refresh or hard refresh the web page and the changes appear there. Can we do the same thing for a Swing applications so that we don't have to close and open the program from the beginning every time we make a change?
I don't think so because you need hot code replacement ! Maybee using another framework.
You can't simply do that because once JVM is started, it loads the class files once and will not reload it untill next loading request. But you can use ClassLoader to load modified class files dynamically.
The following two articles may help:
IBM article on "hot class swap"
"Who Said Runtime Class Reloading Is Hard in Java?"
The first one is in Chinese, but you can look at the code and the result. I think the second article is more helpful for a GUI application.
In MyEclipse you can start your application in debug mode instead of run mode and changes you make will be pushed to the target VM; if changes you make cannot be replaced you'll see a dialog informing you the replace failed and you will need to restart your application. You don't need to place any breakpoints in the application, just starting in debug mode is sufficient.
As Guillaume states above, changes to the class structure will typically not be hot-synched, but changes within existing methods should be fine.
Obviously, how successfully hot-synched changes affect your running application would depend on your application design.

How to programmatically load a desired plugin on eclipse start up

Is there any method in SWT to programmatically set my plugin as default whenever the eclipse IDE starts i.e. when the eclipse starts a desired plugin is set as perspective.
If I remember correctly, it should be possible with setDefaultPerspective(String id).
You can access this via:
PlatformUI.getWorkbench().getPerspectiveRegistry().setDefaultPerspective(id);
However, be careful when doing this. I can imagine that a lot of people might uninstall your plugin, just because they are annoyed by this small change.

Dynamic language switching in an Eclipse RCP application

I am working on an Eclipse RCP application with localization. A user should be able to change the language used in the application on the fly. A restart of the application should not take place during this language switch. It should also be possible to switch between languages written from left to right and languages written from right to left.
Is there a (good) way to solve this problem?
According to this thread:
Most of the eclipse libraries load up their language info on widget creation. If you change your locale afterwards you need to restart eclipse to have it take effect.
You could write that kind of dynamic behaviour into your own SWT program, however (when the locale switches, you'd need to call setText(*) on everything :-)
So this is not currently managed dynamically unless you program it yourself...
Other rcp/plugins application like Birt specify the same instructions (i.e. "Restart Eclipse" at the end...)
That said, a slightly different problem was set in this thread:
switch the language setting, restart, and then run in that language
I got it to work by reading bug 222023 and mimicking org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction
I tried it manually:
added "-configuration #user.home/.myapp/configuration" to the launcher.ini
added "osgi.nl" to the users config.ini residing there and it worked.
Since I can access the config-Location via Platform.getConfigurationLocation() I guess that could be the way.
Note: adding "osgi.nl" to the webstart jnlp works too.
You would need to call setText on each widget, with the respective text. Since there is no text variable mapping on the widgets, you would have to do that completely manually as well.

Categories