Edit Run Configuration Eclipse From Java code - java

I'm sorry if my question seems to be off-topic but I'm new here.
I have to change run configuration eclipse from Java code. I want to run my app with a run configuration (for example: Maven build) and inside of my app I want to edit the current run configuration from maven build to Java application just for a moment.
Is it possible?
Thanks in advance.

Right click on your project and go to Run As and select Run Configurations option in the menu.
A dialog box of Run Configurations will be opened.
Select the required configuration from the left hand side list.
It will open the selected configuration in edit mode.
Make required changes and hit Run.

Related

IntelliJ No Run Button upon right click

I have a series of automated java tests as part of a maven project in java. I have just switched machines from a machine where the tests run fine.
Now, when I right click on the test java class, there is no 'Run', 'Debug' options. Only the main option at the top of the window - which doesn't work either.
I have checked the Junit plug in is installed and I have Invalidated Caches and restarted.
Any ideas?
Thanks
You need to "edit configuration" and add run configuration for your test class.
Here is the example for JUnit but for TestNG it should look similar. You expand the combobox on the top right and choose "Edit Configuration..". Then you add JUnit/TestNG configuration and in configuration details specify the test class to run.

Spring boot devtools - Static content reloading does not work in IntelliJ

When building my first Spring Boot app, I discovered that I need to restart my app every time I make a change to a Javascript file in /resources/static/some-file.js
This is very time consuming.
When I move the files to the /webapps/ folder, it works as expected, but the files are not packaged in a JAR. The docs mention this, so I cannot continue this way.
I read all about spring-boot-devtools, and have installed it in my POM, but the hotswapping doesn't seam to be working. I still need to restart the entire app to see a Javascript or CSS file change.
When the app starts, I can see the line LiveReload server is running on port 35729, so spring-boot-devtools must be doing something...
What would be the steps to further investigate what is going wrong?
My guess is that when IntelliJ runs the app, the files are copied, so when I make a change, I'm actually changing the original files and not the ones used by the running app.
PS: I'm using Maven, IntelliJ IDEA 15 and Spring Boot 1.3.3 with the embedded Tomcat server. I'm not sure what command IntelliJ runs to start the app. The IDE is handling this "automatically". Perhaps I need to change my run configuration?
You need to turn on a couple of features in IntelliJ to make this work.
First, there's a project specific setting which you would need to apply on any project you want to use devtools in. Go to Preferences > Compiler and enable "Make project automatically."
The next setting is an IDEA registry setting that applies to all projects.
In macOS (OSX), press Shift+Command+A (Shift+Ctrl+A in Windows)
Type "Registry" in the search box that appears, and select the registry to open it.
Lookup compiler.automake.allow.when.app.running and enable it.
After that, restart your app. You will notice that the project keeps rebuilding with every change you make. When you check out the result in the browser, you will see both static files and code have been updated.
For Windows users the steps are:
1) Go to File->Settings, then to "Build,Execution,Deployment"->Compiler and enable the "Make project automatically" flag.
2) Press Ctrl-Alt-Shift-/ and select "Registry" from the menu that appears. Enable compiler.automake.allow.when.app.running flag.
3) Start/restart the app and observe static content reloading.
For IntelliJ 2021.2 version or above below are steps that you need to follow
Add spring-boot-devtools dependency if not already added.
Enable Build project automatically as shown below
Enable option in Advanced Settings as shown below
On Linux, press:
Ctrl-Alt-Shift-/
For mac users I had to press Command + Shift + A
And restart INTELLIJ after Step1 and Step2 without which the registry option was not appearing.
You can user like bellow:
First Open Preferences.../Settings... -> Build, Execution, Deployment -> Compiler and allow Build project automatically. Image will look like
Second, we change Registry configuration. Press command+shift+A for macOS or if you are using Windows press Ctrl+Shift+A, and search for Registry. enable compiler.automake.allow.when.app.running.Images look like bellow
Registry image look like..
compiler.automake.allow.when.app.running enable image look like
Then Enjoy..
The option is now in Advanced settings:

Non-existing MySql message error

I have to build a Decision Support System, but dont have much experience in Java. So after I connected to MySql with Eclipse (with Connector/J) eclipse started to mess up my other projects. Now, when i try to run other projects in eclipse (that are not related to MySql, ex. Guessing Game) the following error message apperars:
Launch configuration DocsConnectionPropsHelper references non-existing project MySql connection test.
Can anyone help me to resolve this problem please?
UPDATE. it seems that when i press "RUN" elcipse is not running the project that im working with, but other
Your update indicates the issue is actually running the wrong project. To avoid that you may want to close projects you're not working on (right click them in package explorer and select close).
If you do need multiple projects open then when clicking the run icon (which defaults to re-run whatever was ran last among your open projects) make sure you have open in the editor window something that can be ran (and is from the project you want to run).
Then click the drop down arrow to the right of the icon. This will open up a small menu with options to change your build configurations or how it should run your program (i.e. as an application or on a server).
To solve the problem:
-click right botton on the project package you want to work on (run)
-choose Run As
-choose Run Configurations...
-choose DocsConnectionPropsHelper - if in the Project box you see not correct title just remove it. Also remove anything what is in the Main Class box.
-click Apply
-the best option is to close Eclipse and reopen it to make sure that all the settings were configured
It worked for me. Hopefully it will work for you too.

Java source code not shown in Eclipse debug view

I am doing remote debugging of a Java application and using the debug view of Eclipse. The basic debugging process is working fine and I can see the method stack traces in debug view at the relevant breakpoints. However, I am not seeing the corresponding source code in the tab below and it is saying:
Source not found
The source files are already in my Eclipse project and I can see them in the Java view. I have edited the source look up paths and added the *.java files to it. But even then I am not seeing the source code in the debug view where the execution halts. Any clues on this would be appreciated.
For the Run/Debug configuration that you have been using to Remote Debug, have you followed these steps :
“Run -> Debug configurations…”
Choose the remote config from the tree on the left
Click on the “Source” tab
Click on the “Add…” button
Follow the wizard (add the Project containing the source which is being debugged).
If so, can you post a snapshot of the Run Configuration ?
What I have usually done with a Remote Debug run configuration is Add Source as Java Projects to the Source tab on the Run/Debug configuration. Thus to add a project called so, I would proceed as follows :
And when choosing the project, select the two checkboxes :
To end up with this finally :
I have done the below steps and it worked for me:
Run > Run Configurations
Java Application > Click on Source Tab
Include the project by selecting the option "File System Directory"
Debugging started showing the source code.
You are probably using JRebel which is automatically recompiling and reloading classes. Unfortunately Eclipse Debugger doesn't work with class realoaded in this way. In order to make sure that Eclipse will work fine with the class after changes you have to restart your web application container.

Hook into the Eclipse build process?

I'd like to be able to run a simple Java program when the build button is pressed in Eclipse. Currently when I click build, it runs some JRebel logging code. I have a program that parses the JRebel log file and stores statistics in a DB.
Is it possible to write a plugin or somehow hook into the build process of Eclipse, so that after the JRebel logging is done, it will run my program to parse the file automatically?
Any help would be appreciated, even if you could just point me in the right direction.
Thanks in advance.
You can add a custom Builder to your java project.
Right-click on your project. Select Properties.
In the tree on the left side choose 'Builders'.
You can either add an ant script or specific program. You also have ability to choose when this tool will be running ( before or after Java Builder ).
You can write an incremental project builder and register it via extension point: http://www.eclipse.org/articles/Article-Builders/builders.html

Categories