Search code examples
javamavenportjmx

Failed Maven build remains stuck when using jmx


I'm using (almost) latest Intellij Ultimate 2022.1.1 (same with latest VS Code) with JDK 8 and maven 3.6.3 (can't upgrade)

When executing Maven build (as compile/package) and it fails (for example compilation error)

I can't rerun because port 1100 is still used by a java.exe process I must kill manually

As a work around I kill process in command line dynamically

FOR /F "tokens=5 delims= " %P IN ('netstat -a -n -o ^| findstr :1100') DO TaskKill.exe /F /PID %P

jps output :

RMI Registry not available at 11808:1099
Exception creating connection to: 11808; nested exception is:
        java.net.SocketException: Network is unreachable: connect

**EDIT **

Problem was due to environment variable MAVEN_OPTS jmxremote.port 1100 used for activate JMX for JConsole

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100

Solution

  • Intellij starts maven background process to import dependencies (and other things) and doesn't close it for faster re-run. This background process uses MAVEN_OPTS just like normal maven process and listens port preventing other maven processes from starting

    Remove global MAVEN_OPTS and set -D*.jmxremote.* perameters only for the required process

    • You can set perameters in intellij Run/Debug Configuration

    • When run from terminal: export MAVEN_OPTS="" && mvn package

    • For run tests try this