How to debug a Maven OpenJFX application in IntelliJ - maven

Since JavaFX has become OpenJFX and needs to be added as a dependency to your Maven project, debugging a OpenJFX application has become complicated. In this question it is already answered how to solve it for NetBeans. But IntelliJ works slightly different. The Ppom.xml has been setup according to this example.
How can you run an OpenJFX (JavaFX) application which is configured as a Maven project in debug mode in IntelliJ?

If you would copy the addition of VM options in the pom.xml for javafx-maven-plugin as given by José Pereda here, you can run the application with 'mvn javafx:run#debug' and then manually attach it to the IntelliJ Debugger by go to the menu 'Run - Attach to process...' and the select your application.
However, if you want debugger and application to be started with a single click, IntelliJ is a but troublesome. You can create a Remote Debug configuration which first launches your application and the debugger serially. Or have Compound Configurations which does both in parallel. The problem is to get them synchronized.
I found the following solution. Make your application run as debug client and the IntelliJ debugger as server. The VM options for the javafx-maven-plugin in the pom.xml file should have 'server=n':
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<!-- Default configuration for running -->
<id>default-cli</id>
<configuration>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
<execution>
<!-- Configuration for debugging -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8000,suspend=y</option>
</options>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Create a Maven Run Configuration in IntelliJ with 'javafx:run#debug' in the 'Command line'.
Create a Remote Run Configuration with the following settings:
Debugger mode: 'Listen to remote JVM';
Transport: 'Socket';
Host: as in the pom
Port: as in the pom
Now the Remote Run Configuration will start a debug server waiting for clients. The Maven Run Configuration will connect to the debug server, or fail if the debug server isn't online.
Now, to get everything started with a single click, you can create a Compound Run Configuration and add the Maven and the Remote Run Configuration to it. Starting this configuration will launch the two in parallel, and you can debug your application.

Related

Running Spring Boot "context loads" test in maven causes OutOfMemoryError

I have a multi-module Maven project with two modules being Spring Boot applications. Each of them has a simple test that the Spring application context loads successfully (my tests are very similar to this one). I run this tests with the following command in project root:
mvn -P IntegrationTests clean test
During context initialization things go out of my control, the application "eats" memory (heap size grows quickly to 4 gigabytes) and then the context fails to start with java.lang.OutOfMemoryError: PermGen space error (yes, I run it in Java 7).
Monitoring task manager during testing I noticed that maven spawns two new processes that have something to do with surefire plugin. I have no idea where it comes from, because I don't add the surefire plugin in my pom.xml.
Previously when encountered the same error somewhere I specified VM options (-Xmx256m -Xms128m -XX:MaxPermSize=256m -XX:PermSize=128m for example) and the problem was solved.
This time I tried to
set MAVEN_OPTS environment variable
set VM options (when running mvn test in IntelliJ IDEA) - it affected main java process but not its children
add -Drun.jvmArguments="..." in command line
but the problem persists.
Please help me to fight the OutOfMemoryError in tests.
Add Surefire plugin explicitly to module-specific pom.xml and configure VM options there. I like this solution because this way VM options are
passed to the spawned surefire processes (which should solve your problem)
affect only test application builds
shared between developers in your team
configurable independently for every module
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx256m -Xms128m -XX:MaxPermSize=256m -XX:PermSize=128m</argLine>
</configuration>
</plugin>
<!-- your other plugins go here -->
</plugins>
</build>

GWT + Maven + Tomcat + JNDI + Eclipse configuration

I've got a project using GWT 2.6.1 + Maven 3.2 + Tomcat 5.5 (yes, I know it's an old one ...) + Eclipse Luna which is using JNDI allowing for external parameters to be configured.
As you might know, the context XML file is located at /conf/Catalina/localhost/myWebApp.xml where myWebApp is the Java web application name.
I am using gwt-maven-plugin for this project (the one from mojo haus) which has the version 2.6.1.
Here is my current configuration :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<module>xxx.yyy.myModuleName</module>
<runTarget>myWebPage.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<encoding>UTF-8</encoding>
<failOnError>true</failOnError>
<style>OBF</style>
<i18nMessagesBundle>xxx.yyy.zzz.client.ui.i18n.OlbClientMessages</i18nMessagesBundle>
<extraParam>true</extraParam>
<extraJvmArgs>-Dgwt.compiler.optimizationLevel=9</extraJvmArgs>
<extraJvmArgs>-Xms128M</extraJvmArgs>
<extraJvmArgs>-Xmx1200M</extraJvmArgs>
<extraJvmArgs>-XX:MaxPermSize=768M</extraJvmArgs>
<noServer>true</noServer>
<logLevel>INFO</logLevel>
</configuration>
</plugin>
As you can see, i am using the noServer (configured to "true") option because I must use an external Tomcat container for the server side.
My question is :
How can I enable client side AND server side debugging within my actual configuration through a step-by-step help.
I've made a lot of attempts but i can't make things working.
I've tested running the "mvn gwt-debug" which tries to connect to default port 8000 and then connecting a remote java application which connects to my webapp to localhost:8000 and it works well, but it's only for the server side.
I also need to debug the client side in the DEVMODE.
Thanks for your help.
There are two ways to run a remote server. First is using using DevMode with -noserver and pointing the war directory to the output war directory of the external server. The second way is to use the CodeServer entrypoint and run a WTP server runtime and set the launcher directory to tomcat output war directory.
I prefer the second routine, and built automation into the GPE fork.
http://gwt-plugins.github.io/documentation/gwt-eclipse-plugin/servers/Tomcat.html - see it in action here. There are videos and such.

autoweaving AspectJ fails during unit tests in IntelliJ

We have a series of unit tests and they were passing fine prior to me trying to add some aspects for dependency injection and logging duration of methods being called in our rest end points.
In the unit tests prior to the tests failing, we get two odd errors:
[AppClassLoader#14dad5dc] error aspect 'com.lutherconsulting.aphirm.log.DurationLoggingAspect' woven into 'com.lutherconsulting.aphirm.rest.ClientRest' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).
and
[AppClassLoader#14dad5dc] error aspect 'com.lutherconsulting.aphirm.log.DurationLoggingAspect' woven into 'com.lutherconsulting.aphirm.log.DurationLoggingAspect' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).
We are using the aspectj maven plugin to just let it autoweave the aspects into the web application. The configuration for that from our pom.xml for Maven is below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The strange thing is that this all works perfectly fine if I build the war file and deploy it to a Tomcat instance, or if I run all of our cucumber feature tests. When I do either of those, The aspect weaves fine and I get data on the duration of the rest methods I annotated logged to a database correctly. If I run a specific test package from intelliJ or try to run all junit tests in intellij, it fails with those two errors
Is this something I'm just missing in Intellij as a run/debug configuration in the way it executes unit tests? I didn't think our structure of our app was different than any normal web app
- src
| - main
| - java
| - packages
| - resources
| - test
| - java
| - packages
| - resources
- pom.xml
I appreciate any ideas on
In the end, what turned out to fix this was to go into the project structure in IntelliJ, on the AspectJ settings there is a check box for Post-Compile Weave Mode. Checking this made sure weaving occurred in Intellij prior to the tests executing.
As far as I understand you are running your tests from IntelliJ using its own runner and not maven.
Therefore you have configured the weaver to be run using maven through the aspectj-maven-plugin. The problem is that your IntelliJ runner is not running maven, hence its weaver plugin is not being run either.
I can come up with an idea and you could run your maven test goal within IntelliJ to run all your tests with the maven configuration, so it will detect aspectj-maven-plugin and run the weaver too. Here you can check how to run maven goals:
https://www.jetbrains.com/idea/help/executing-maven-goal.html
On the other hand, according to this link you have to enable Load Time Weaving in IntelliJ
http://www.aspectprogrammer.org/blogs/adrian/2006/02/a_practical_gui_2.html
Quoting the link it says:
Open the "Run/Debug Configurations" dialog using the drop-down in the
toolbar. Click the "+" icon to create a new configuration and name it
e.g. "tests".
For this project, I've selected "All in package" and search for tests
"In whole project".
Now all you have to do is add the VM startup parameter that brings in
the AspectJ LTW agent:
-javaagent:lib/aspectjweaver.jar
The part after the ":" should be the path to your copy of aspectjweaver.jar. In this case, I've copied the
aspectjweaver.jar from the Spring distribution into the lib directory
of my project (it doesnt' need to be on the project's classpath). You
can use the jar from AspectJ 5 final release too if you want to.
Also, you can check to configure AspectJ facet, check this link to read about it
https://www.jetbrains.com/idea/help/aspectj.html

Debug web app in IntelliJ, webapp built by maven, run by jetty

I'm using s/o code, it's a java webapp built by maven. The webapp is run by maven script, like below, and the app is run on localhost:8080, :
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<contextPath>/</contextPath>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<!--<port>8085</port>-->
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<stopKey>stop</stopKey>
<stopPort>8089</stopPort>
</configuration>
</plugin>
</plugins>
</build>
I want to attach the debugger of IntelliJ so that I can step through the code. I tried to set up a debugger configuration like: Jetty Server, then 'Remote' but it said Application Server not specified. I also tried with 'Local', it said 'main config file not included'.
So what must I do to attach the debugger?
Thanks in advance.
The easiest way is to:
Expand your project in the Maven Projects tab.
Expand Plugins > jetty items.
Right-click jetty:run.
Choose Debug from the context menu.
I know it's too late to reply this question, but It's worth sharing the latest update on this issue as a modern solution: You can also run jetty using “mvnDebug jetty:run” which has the same effect. Which display the following logs in the terminal
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
[INFO] Scanning for projects...
Just remember to choose the correct socket address(e.g. 8000), then:
Open Intellij
Run -> Edit Configuration
In Run/Debug Configuration window, you need to click on (+) button to add a new configuration
Select Remote
Keep the default configuration as is, just change the listening port to corresponding one (8000).
Enjoy.
When I was getting "main config file not included" it was because the path to Jetty in my Application Server configuration (on Run/Debug Configurations dialog) was deleted during my OS X upgrade (I had put it in /usr/share/java).
I reinstalled jetty-hightide-8.1.5.v20120716 under /usr/local, updated the configuration and all is well.

maven cargo plugin configuration for Jboss as 7.1.0

I am trying to configure the maven cargo plugin for deployment on existing jboss 7.1.0 on my local machine. I am able to start the server by
mvn cargo :run command. It is using the jboss-modules.jar to start the server. I want to configure it in such a way that it executes the standalone.bat inside the bin to start the server. I have my datasource configured in standalone.conf.bat and hence I need to execute the standalone.bat to start and deploy the war.. My configuration looks like this..
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<wait>true</wait>
<container>
<containerId>jboss7x</containerId>
<home>C:/jboss-as-7.1.0.Final/</home>
</container>
<configuration>
<type>existing</type>
<home>C:/jboss-as-7.1.0.Final/standalone</home>
</configuration>
</configuration>
Is there any property in cargo configuration to set to call the standalone.bat to start the server?
Thanks,
The question is a bit outdated, however with the current release of JBoss Maven plugin it is actually possible to start and stop the application server using mvn jboss-as:start and mvn jboss-as:shutdown commands. I have added a Maven JBoss tutorial time ago describing exactly this.

Resources