How to debug OFBiz in IntelliJ IDEA - debugging

I have try to debug OFBiz in IntelliJ IDEA. But I couldn't find any particular document for that. So first I try to configure debugging OFBiz in Eclipse and then try to debug OFBiz in IntelliJ with same configuration. It's working with Eclipse but it did not work with IntelliJ.
What I have Done:
Run > Edit Configuration
Then select Application
Configuration option:
Main class: org.ofbiz.base.start.Start
VM option: -Xms128M -Xmx512M
Working directory: (path of the OFBiz project)
Use classpath of module: Project directory (i.e ofbiz)
What should be the right configuration for debugging OFBiz in IntelliJ. If anyone can provide a link(where this is documented) then it also will be helpful.

Run/Debug Configurations -> Add New Configuration -> Jar Application -> Then you should set Path to ofbiz.jar and working directory
For me it works good

Related

Spring Dev Tools not Restarting After Making Changes in IntelliJ

I am building some backend APIs using Spring Boot and Kotlin.
My build tool is Gradle
My IDE is IntelliJ Ultimate Edition on a Windows Machine
I have included the spring boot dev tools into my build.gradle.kts dependencies as follow:
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
But whenever I make a change while the server is running, it doesn't automatically reflect the changes.
Is there anything else I need to do?
Thanks
Enable “Build project automatically” option in compiler settings.
1 - You need to enable the “Make project automatically” option:
You can find it in Settings –> Build, Execution, Deployment –> Compiler
2 - Changes in IntelliJ registory:
Go to Cmd+Shift+A (Mac) or Ctrl+Shift+A (Windows) -> Registry Enable compiler.automake.allow.when.app.running

Run Corda project on IntelliJ

I'm using a MacBook Air OS X 10.9 (Mavericks) and IntelliJ IDEA, but the IDE won't let me execute the test "ProjectImportedOKTest" which is in src/test/java/java_bootcamp/. I followed the exact same steps of this video:
https://www.youtube.com/watch?v=ZgKxjwImKAs&index=3&list=PLi1PppB3-YrVq5Qy_RM9Qidq0eh-nL11N
But for some reason my green arrow to run the test is always disabled. It could be something with the configuration option in the top left of IntelliJ, which I left blank or even something with gradle.
Thanks a lot!!
You can invalidate the caches of the intelliJ by using the option
file -> invalidate caches/Restart.
It helped for me.
There are several things you could try.
Ensure that your source java or kotlin folder is marked as "Sources Root". Do this by right clicking the folder and selecting "Mark Directory as"
Go to view -> Tool Windows -> Gradle and hit the refresh icon
Try opening the project a different way, such as importing the project or just opening the project
Rebuild the project and ensure there are no errors
Go to File -> Project Structure and ensure Java 1.8 is set as the Project SDK
Got to File -> Settings 0> Build, Execution, Deployment and select Gradle. Ensure Gradle JVM has Java 1.8 and that "Use default gradle wrapper" is selected.
Again under Settings and Build, Execution, Deployment, go to Compiler -> Kotlin Compiler and check that Target JVM version is set to 1.8
I ran into the same problem running on Windows and ran into this question trying to find the solution. It turns out Gradle wasn't installed on my machine and that was causing the problems.
According to the Corda Docs - "Gradle - we use 4.10 and the gradlew script in the project / samples directories will download it for you."
However, I installed from the Gradle website here - https://gradle.org/install/#with-a-package-manager -and configured it in the PATH variable. After doing so, my green arrow was enabled and I was able to run the test successfully.

how to set spring active profile environment variable in IntelliJ

I am using spring boot application (maven project) in eclipse. When I run test clean target of maven project, I want to load the active profiles
I have added the property spring.profiles.active=test,aop in application.properties and also in application-test.properties, this does not have any affect.
or setting this property in command line option of IntelliJ IDE as -Dspring.profiles.active=test,aop does not have an effect when the command is test clean. I have also tried setting the JVM argument of the Runner in Intelligent
however #ActiveProfiles("test") works when the test case class is executed from IntelliJ IDE( right click -> run TestCaseClass).
Any clues ?
Setting the VM Options with -Dspring.profiles.active=test
My Project is using MAVEN.
the easy was is
Right hand side click on MAVEN -> Expand the Profiles -> Click on desired profile.
Build and run
Please check the attached screenshot for more clarity

How do I activate a Spring Boot profile when running from IntelliJ?

I have 5 environments:
- local (my development machine)
- dev
- qc
- uat
- live
- staging
I want different application properties to be used for each environment, so I have the following properties files each which have a different URL for the datasource:
- application.properties (containing common properties)
- application-local.properties
- application-dev.properties
- application-qc.properties
- application-uat.properties
- application-live.properties
I am using IntelliJ and running my app using bootRun in the Gradle plugin on my local machine. I will be using deploying the same application war file on all other environments which run Tomcat.
I have tried adding:
--spring.profiles.active=local
to the run configuration under script parameters.
I have tried adding
-Dspring.profiles.active=local
to the run configuration under VM options.
Neither work. I keep seeing the INFO message on startup say: No active profile set, falling back to default profiles: default
If I run my app from the windows command line using
gradle bootRun
but I first set the environment variable
set SPRING_PROFILES_ACTIVE=local
Then everything works.
So my question is, how do I activate my local spring boot profile when running bootRun from IntelliJ ?
I added -Dspring.profiles.active=test to VM Options and then re-ran that configuration. It worked perfectly.
This can be set by
Choosing Run | Edit Configurations...
Go to the Configuration tab
Expand the Environment section to reveal VM options
If you actually make use of spring boot run configurations (currently only supported in the Ultimate Edition) it's easy to pre-configure the profiles in "Active Profiles" setting.
Spring Boot seems had changed the way of reading the VM options as it evolves. Here's some way to try when you launch an application in Intellij and want to active some profile:
1. Change VM options
Open "Edit configuration" in "Run", and in "VM options", add: -Dspring.profiles.active=local
It actually works with one project of mine with Spring Boot v2.0.3.RELEASE and Spring v5.0.7.RELEASE, but not with another project with Spring Boot v2.1.1.RELEASE and Spring v5.1.3.RELEASE.
Also, when running with Maven or JAR, people mentioned this:
mvn spring-boot:run -Drun.profiles=dev
or
java -jar -Dspring.profiles.active=dev XXX.jar
(See here: how to use Spring Boot profiles)
2. Passing JVM args
It is mentioned somewhere, that Spring changes the way of launching the process of applications if you specify some JVM options; it forks another process and will not pass the arg it received so this does not work. The only way to pass args to it, is:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="..."
Again, this is for Maven.
https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html
3. Setting (application) env var
What works for me for the second project, was setting the environment variable, as mentioned in some answer above: "Edit configuration" - "Environment variable", and:
SPRING_PROFILES_ACTIVE=local
Tested with IntelliJ Community edition 2021.x
You can create Multiple configurations, one each for a specific profile, In my case below, I have created a dev config with dev profile environment variable.
Goto Run > Edit Configuration
Choose the configuration you want to edit, in the left under Application.
On the right side > Under Environment Variable, update spring.profiles.active=<your profile name> example
spring.profiles.active=dev
(observer:- the variable should be without -D flag)
Save the changes and Run the Spring boot app with the same configuration.
Note:- You can also create a new configuration or copy existing in step 2 above, using the option available in the same panel.
Try add this command in your build.gradle
So for running configure that shape:
For Spring Boot 2.1.0 and later you can use
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
I ended up adding the following to my build.gradle:
bootRun {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "local"
}
test {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "test"
}
So now when running bootRun from IntelliJ, it defaults to the "local" profile.
On our other environments, we will simply set the 'SPRING_PROFILES_ACTIVE' environment variable in Tomcat.
I got this from a comment found here: https://github.com/spring-projects/spring-boot/pull/592
A probable cause could be that you do not pass the command line parameters into the applications main method. I made the same mistake some weeks ago.
public static final void main(String... args) {
SpringApplication.run(Application.class, args);
}
I use the Intellij Community Edition.
Go to the "Run/Debug Configurations" > Runner tab > Environment variables > click button "...". Add:
SPRING_PROFILES_ACTIVE = local
spring.profiles.active
In my case I used below configuration at VM options in IntelliJ , it was not picking the local configurations but after a restart of IntelliJ it picked configuration details from IntelliJ and service started running.
-Dspring.profiles.active=local
So for resuming...
If you have the IntelliJ Ultimate the correct answer is the one provided by Daniel Bubenheim
But if you don't, create in Run->Edit Configurations and in Configuration tab add the next Environment variable:
SPRING_PROFILES_ACTIVE=profilename
And to execute the jar do:
java -jar -Dspring.profiles.active=profilename XXX.jar
Try this. Edit your build.gradle file as followed.
ext { profile = project.hasProperty('profile') ? project['profile'] : 'local' }
You can try the above way to activate a profile
Here are 2 ways
Using gradle project property
In build.gradle, add
bootRun{
//https://github.com/spring-projects/spring-boot/pull/592#issuecomment-880263914
if (project.hasProperty('profiles')) {
environment SPRING_PROFILES_ACTIVE: profiles
} else {
def profiles = 'dev'
environment SPRING_PROFILES_ACTIVE: profiles
}
}
In intellij gradle configuration, change the value "test" in "-Pprofiles" as appropriate to environment you want to run
Using environment property
Follow answer by #Hubert https://stackoverflow.com/a/39749545/3333878
And configure the run configuration as
Create files properties like these
application.properties
application-dev.properties
application-prod.properties
then run
VM option is hidden by default.
Here is the right way to do it
Run->Edit Configurations->Select the application on the left menu->Add VM Options
and then add
-Dspring.profiles.active=<profile_name>
Replace the <profile_name> with the profile, say local
Click Apply & OK.
Set -Dspring.profiles.active=local under program arguments.

How can I debug scala source code in IDEA with SBT Jetty-run?

I found related answer in Debugging Scala code with simple-build-tool (sbt) and IntelliJ . But I still don't get it. Does it mean I need to first config the following in sbt.bat
set SCRIPT_DIR=%~dp0
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -Xmx512M -jar "%SCRIPT_DIR%sbt-launch-0.7.5.RC0.jar" %*
And then launch the "Remote" in Run/Debug configurations in IDEA all with default?
After those two steps, the program can stop in the breakpoint when I refresh my web application page?
See my answer in the related question:
Debugging Scala code with simple-build-tool (sbt) and IntelliJ

Resources