Netbeans Profiler: Connecting to the target vm forever

I found out the profiler works if I attach it dynamically. Therefor you have to start the application first (with a break point). Then you click Profile > Attach Profiler... In the top select your project and attach a local dynamical profiler. If you already created the wrong one you can change it at the bottom of the Attach Profiler dialog. Now select the running process and that's it.


I had the same problem using NetBeans 8.0.2 to profile a junit test in a multi-module maven project.

I worked around it by extracting the test into a standalone maven project and adding the other modules as dependencies.

The reason it doesn't work in the multi-module project is that when clicking Profile Test File NetBeans generates an incorrect command line. E.g. in the multi-module project, it produces:

cd C:\test; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_40" cmd /c "\"\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven\\bin\\mvn.bat\" -Dtest=PerfTest -DforkMode=once -Dmaven.surefire.debug=${exec.args} -Dexec.args= -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 surefire:test\""

whereas it should be:

cd C:\test; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_40" cmd /c "\"\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven\\bin\\mvn.bat\" -Dtest=PerfTest -DforkMode=once -Dmaven.surefire.debug=${exec.args} -Dexec.args=\"-agentpath:\\\"C:/Program Files/NetBeans 8.0.2/profiler/lib/deployed/jdk16/windows-amd64/profilerinterface.dll\\\"=\\\"C:\\Program Files\\NetBeans 8.0.2\\profiler\\lib\\\",5140,10 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\\Users\\foo\\AppData\\Local\\NetBeans\\Cache\\8.0.2\\mavencachedirs\\2029222463\\org-netbeans-modules-profiler  \" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 surefire:test\""

TL;DR - the -Dexec.args= argument is empty in the multi-module project.